Storing and passing all iterations to an array outside the nested for loops
Ältere Kommentare anzeigen
Hello, my problem is basically that I don't know how to store and pass all 8736 different values from L(k) to the outside of nested for loops in a form of an array (8736x1), so I can use it for further processing and comparing with some other arrays in my code. Code is below...
Lw =[52x1]; Ld=[7x1]; Lh=[24x6]; Ly=number;
for i=1:length(Lw)
for j=1:length(Ld)
for k=1:length(Lh)
if ((i>=1 && i<=8)||(i>=44 && i<=52))
if (j>=1 && j<=5)
L(k)=Lw(i)*Ld(j)*Lh(k,1)*Ly;
else
L(k)=Lw(i)*Ld(j)*Lh(k,2)*Ly;
end
end
if (i>=18 && i<=30)
if (j>=1 && j<=5)
L(k)=Lw(i)*Ld(j)*Lh(k,3)*Ly;
else
L(k)=Lw(i)*Ld(j)*Lh(k,4)*Ly;
end
end
if (i>=9 && i<=17)||(i>=31 && i<=43)
if (j>=1 && j<=5)
L(k)=Lw(i)*Ld(j)*Lh(k,5)*Ly;
else
L(k)=Lw(i)*Ld(j)*Lh(k,6)*Ly;
end
end
L(k)
end
end
end
L to be passed here with all 8736 values
Thank you in advance.
Akzeptierte Antwort
Weitere Antworten (1)
Image Analyst
am 23 Dez. 2019
Bearbeitet: Image Analyst
am 23 Dez. 2019
0 Stimmen
L is available after all the loops terminate. It does not exist solely inside the loop and then vanish when the loops end. Simply pass L to your other code for further processing.
If you don't want to overwrite L on the inner loop, simply add additional indexes L(i, j, k).
3 Kommentare
Banjo
am 23 Dez. 2019
Image Analyst
am 23 Dez. 2019
If you don't want to overwrite L on the inner loop, simply add additional indexes L(i, j, k).
Banjo
am 23 Dez. 2019
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!