Change variable name on each iteration in for loop MATLAB

4 次查看(过去 30 天)
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

采纳的回答

Shaun VanWeelden
Shaun VanWeelden 2013-3-14
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 个)

类别

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