# Saving a loop array

1 view (last 30 days)
Joshua Welsh on 16 Dec 2016
Closed: Joshua Welsh on 8 Jun 2018
I'm trying to save a loop array, each output (BeadC & BeadS) produces a 9x1801 double - I would like to save each iteration so it is 9x1801, 18x1801 etc. Currently it is producing the correct sizes but they are just repeats of the same data. What do I need to edit?
lam =[405 488]; % Wavelength of scatter (nm)
n=length(lam);
for t=1:n
nx= length(openang_range); % number of angles to calculate collection for
jj=t*ny;
kk=jj-(ny);
c=length(b(:));
for j=1:ny
for ii=j:kk:c
end
end
end

Show 1 older comment
Joshua Welsh on 18 Dec 2016
The Bead_SSC, Bead_RI and Bead_nm are related there will be the same number of them (usually 9 each) all each time, and are lam(t) specific. before.
if true
end
So if there is 1 lam variable there will be one set (1x9) going into the Length1 function, I am trying to go up to 4 lam so producing 4x9 sets calculated for each of the open open_range (1x1801) variable.
Image Analyst on 18 Dec 2016
Make it easy for us to help you, not hard. That means making it so that we can run your code. Please give us values for the missing variables so we can do that, like John already asked you for.
Joshua Welsh on 18 Dec 2016
Sorry, I can't put all of the code in, there are 20 odd scripts. This is the main one.

Joshua Welsh on 19 Dec 2016
I have fixed this by flattening the matrix and labelling with my first loop.
lam =[405 488]; % Wavelength of scatter (nm)
n=length(lam);
for t=1:n
nx= length(openang_range); % number of angles to calculate collection for
jj=t*ny;
kk=jj-(ny);
c=length(b(:));
for j=1:ny
end
end

Jan on 17 Dec 2016
Edited: Jan on 17 Dec 2016
The right hand side of the innermost loop does not depend on the loop counter ii:
Therefore the results must be repeated. I cannot guess where the dependency to ii must be inserted.
Note: Use the more efficient c=numel(b) instead of c=length(b(:)).