matlab - Counting individual iterations in a nested loop? -


i have following problem. have initialized variable contains 20 cells, each cell contain matrix. generation of matrix done via nested loop so, have:

matrices = cell(1,20);         1:4     1:5         *do stuff matrix*      end end 

i want able save nth result in cell...so example

for outer loop 1, inner loop 1 ---> 1st element of cell

for outer loop 1, inner loop 2 ---> 2nd element of cell

etc, etc.

i know involve incorporating

 matrices{counter} = result; 

somewhere in loop, don't know include , how initiate counter. can't have

for 1:20  

at beginning of loop, because same task 20 different times , not save proper result.

you can either use counter outside of outer loop or can calculate current_index @ each iteration:

matrices = cell(1,20);   counter = 1; k=1:4     j=1:5         matrices{counter} = zeros(k,j);         disp(counter);        counter = counter+1;         current_index = (k-1)*5+j;        disp(current_index);     end end 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -