Change variable name on each iteration in for loop MATLAB
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I have large array P which is changing size and values in each iteration. I need to be able to change the title of my output array to match the given iteration, i.e. for bin 1.4 I would like output to be p1.4 or p14.
Can anyone help?
for bin = 1:0.1:2;
rows = find(DAT(:,27) > bin);
p{bin} = DAT(rows,:);
end
0 Kommentare
Akzeptierte Antwort
Shaun VanWeelden
am 14 Mär. 2013
If you changed the name, you would be making a new variable every time and I am not sure it is even possible to do this like you say, instead, here are two solutions:
N = the number of large arrays you have
Make a N x 2 cell array, collectionArray, put the large array in collectionArray{i,1} and the name in collectionArray{i,2} that way the name is easy to retrieve with the information.
Or Make a collectionStruct, and have a field for each array (named p14, etc.) and have your array be the value in that field, so to retrieve the data, you could just say collectionStruct.p14
Hope it helps!
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!