Storing values from inside the third loop to a variable outside the loops
Show older comments
Hi all,
Is it possible to store values from the inside of a third for loop into a variable which is outside the loops? For instance I have this code:
a = 2:1:5;
b = [1 1.2 2 2.3 3 3.3 4 5];
final_data = [];
for ii=1:length(a)
c = rand(3,8);
for jj=1:length(b)
c_data = c(:,jj);
if (a(ii) > b(jj) )
for xx = 1:length(c_data)
final_data(xx,ii) = c_data(xx);
end
end
end
end
and I want the values in 'c_data' to be stored inside 'final_data' as rows (the columns are determined by the value of ' ii ' ) for every 'jj' value. But it so happens that the values get over-written for every ' jj ' loop iteration. Or in other words, I was looking for a way to vertically append c_data to final_data for every jj loop iteration without being overwritten.
Thanks
Accepted Answer
More Answers (0)
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!