Effacer les filtres
Effacer les filtres

Merge a variable name with a running index from a loop?

3 vues (au cours des 30 derniers jours)
Ines
Ines le 18 Mai 2012
Hi there, I want to save data generated within a loop in a set of variables, whereas I want the variables to have the running index attached to it. How can I do that?
Example:
for i=1:10
result=i^2
variable1=result =>>!! here I want to define sth that makes matlab create a variable name variable+i
end
Many thanks in advance!

Réponses (1)

Jan
Jan le 18 Mai 2012
Don't do this.
It is much nicer, easier, and more reliable to debug to use a cell instead:
a = cell(1, 10);
for i = 1:10;
a{i} = result;
end

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by