Change variable name on each iteration in for loop MATLAB
2 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Shaun VanWeelden
on 14 Mar 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 Comments
More Answers (0)
See Also
Categories
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!