필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

changing the name of a variable

조회 수: 1 (최근 30일)
joseph Frank
joseph Frank 2011년 7월 16일
마감: MATLAB Answer Bot 2021년 8월 20일
Hi,
I know that what I am asking for is not recommended but I need it. I have a loop and i want to change the name of the variable according to the loop:
for i=1:40 variable L I want it to be named L1,L2...L40 according to the i value in the loop.is it possible to do so?

답변 (2개)

Vishwajith Upendra
Vishwajith Upendra 2011년 7월 17일
Here is a sample code which does what you want. Try it.
for i=1:5
x=num2str(i); % Converts number to string
x1=strcat('L',x); % Concatenates your prefix to the varying number
x1 % I guess, this is the variable you want
end
Hope it helped.
  댓글 수: 1
Oleg Komarov
Oleg Komarov 2011년 7월 17일
I think it's more likely to be the faq 4.6 as Walter suggested, otherwise the OP should be more specific.

Walter Roberson
Walter Roberson 2011년 7월 16일
Please see the FAQ
Why do you "need" to do this? There is almost always a better way.
  댓글 수: 3
Paulo Silva
Paulo Silva 2011년 7월 16일
that's the reason for the existence of cells
Walter Roberson
Walter Roberson 2011년 7월 16일
Sounds like a reason to use dynamic field names on a structure, and to use the '-struct' option of save()

이 질문은 마감되었습니다.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by