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

2 views (last 30 days)
the loop running should produce N outputs with each having label A1,A2,A3....An

Answers (1)

CS Researcher
CS Researcher on 1 May 2016
You can use eval. Try this:
for i = 1:10
eval(['A' num2str(i) ' = i;']);
Stephen23 on 1 May 2016
Edited: Stephen23 on 19 Jun 2019
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.

Sign in to comment.


Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by