Save arrow vector which changes its length during a loop

Hey!
I'm trying to save on my workspace an arrow variable (I & J) which shanges its length during the loop.
Hope you can help me!
for i=1:6
DR_min(i)=min(DR_new);
[row]=find(DR_new==DR_min(i));
I=IQ(row);
J=JQ(row);
DR_new(DR_new<=DR_min(i)) = NaN;
shells(i)=length(I)/16;
end

3 Comments

I am not sure what your question is. If it is a matter of saving all the I and J values in the workspace, just index them like this;
for i=1:6
DR_min(i)=min(DR_new);
[row]=find(DR_new==DR_min(i));
I(i)=IQ(row); %added (i) index
J(i)=JQ(row);
DR_new(DR_new<=DR_min(i)) = NaN;
shells(i)=length(I)/16;
end
If I and J change their size you should use a cell array:
I = cell(1,6);
J = cell(1,6);
for i=1:6
DR_min(i)=min(DR_new);
[row]=find(DR_new==DR_min(i));
I{i}=IQ(row);
J{i}=JQ(row);
DR_new(DR_new<=DR_min(i)) = NaN;
shells(i)=length(I)/16;
end
Thank you guys, it helped me a lot, cell array helped me!

Sign in to comment.

Answers (0)

Categories

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

Asked:

on 18 Feb 2020

Commented:

on 19 Feb 2020

Community Treasure Hunt

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

Start Hunting!