Saving a loop array

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
ny= length(Bead_SSC(t,:))*length(lam(t)); % length of all beads being calculated
jj=t*ny;
kk=jj-(ny);
b=(zeros(size(Bead_nm)));
c=length(b(:));
BeadC = zeros(c,nx);
BeadS = zeros(c,nx);
for j=1:ny
for ii=j:kk:c
[BeadC(ii,:), BeadS(ii,:)] = Length1(Bead_nm(t, j), Bead_RI(t, j), lam(t), k0(t), n_wat(t), openang_range); % Collect or Create Predicted Data for Analysed Flow Cytometry Beads
end
end
end

4 Kommentare

John BG
John BG am 16 Dez. 2016
Bearbeitet: John BG am 16 Dez. 2016
why do i have the impression that there's no need for the 2 for loops at the end?
would you please specify values for variables
  • openang_range
  • Bead_SSC
  • Bead_nm
?
it' hasn't got to be the actual value you use but I would like to reproduce your code with similar values to the ones used by you.
Joshua Welsh
Joshua Welsh am 18 Dez. 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
[Bead_nm(t,:), Bead_RI(t,:), Bead_SSC(t,:), Bead_nm_CV(t,:), Bead_SSC_CV(t,:)]=Acquired_Bead_Database(lam(t)); % Collect Flow Cytometry Bead Data
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
Image Analyst am 18 Dez. 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
Joshua Welsh am 18 Dez. 2016
Bearbeitet: Joshua Welsh am 18 Dez. 2016
Sorry, I can't put all of the code in, there are 20 odd scripts. This is the main one.

 Akzeptierte Antwort

Joshua Welsh
Joshua Welsh am 19 Dez. 2016

0 Stimmen

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
ny= length(Bead_SSC(t,:))*length(lam(t)); % length of all beads being calculated
jj=t*ny;
kk=jj-(ny);
b=(zeros(size(Bead_nm)));
c=length(b(:));
BeadC = zeros(ny,nx);
BeadS = zeros(ny,nx);
for j=1:ny
[BeadC(ii,:), BeadS(ii,:)] = Length1(Bead_nm(t, j), Bead_RI(t, j), lam(t), k0(t), n_wat(t), openang_range); % Collect or Create Predicted Data for Analysed Flow Cytometry Beads
end
BeadC1(t,:)=BeadC(:)'
BeadS1(t,:)=BeadS(:)'
end

Weitere Antworten (1)

Jan
Jan am 17 Dez. 2016
Bearbeitet: Jan am 17 Dez. 2016

0 Stimmen

The right hand side of the innermost loop does not depend on the loop counter ii:
Length1(Bead_nm(t, j), Bead_RI(t, j), lam(t), k0(t), n_wat(t), openang_range);
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(:)).

2 Kommentare

Joshua Welsh
Joshua Welsh am 18 Dez. 2016
Thanks for your comment. I understand this is where the problem is, I am trying to save the second loop of t, but currently it is overwriting the first set of results. I'm unsure of how to save the next loop. I assumed it would be adding an inner loop telling the t loop to save the results generated from the j loop further down?
Jan
Jan am 18 Dez. 2016
I have no idea. I cannot imaging, what the loops should do. I only see, what they do and that they do it repeatedly.

Diese Frage ist geschlossen.

Gefragt:

am 16 Dez. 2016

Geschlossen:

am 8 Jun. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by