How can I get dynamic naming variables? So in a loop i need variables with names A1,A2,A3...... logic?

조회 수: 1 (최근 30일)
the loop running should produce N outputs with each having label A1,A2,A3....An

답변 (1개)

CS Researcher
CS Researcher 2016년 5월 1일
You can use eval. Try this:
for i = 1:10
eval(['A' num2str(i) ' = i;']);
end
  댓글 수: 2
ck
ck 2016년 5월 1일
so I have An = strcat(1,2,3..) and n in the loop where It should go as A1,A2.....
can I use eval for that?
Stephen23
Stephen23 2016년 5월 1일
편집: Stephen23 2019년 6월 19일
Note that this forces you into writing slow, buggy, obfuscated code, that removes all of MATLAB code checking abilities and makes code difficult to debug.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by