Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

How to store every matrix values that it's element changed in multiple loop

1 Ansicht (letzte 30 Tage)
Titin Abdurrahman
Titin Abdurrahman am 7 Aug. 2018
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
Hi there, it's been months trying to solved it. However, i got stuck. Suppose i got multiple loops
Z = rand(10,10);
for i=1:s
for j=1:t
for k=1:u
x=1+(k-1).*u+(j-1).*t+(i-1).*s
Z(Z<=y(x)&Z>y(x-1))=w(x);
end
end
end
I only got the last of Z. I would like to store the matrix Z(u,:,:). Thank in advance

Antworten (1)

Bob Thompson
Bob Thompson am 7 Aug. 2018
My best advice for saving the different values of Z is to add an extra dimension that ticks up each loop.
Z(Z<=y(x)&Z>y(x-1),k,j,i)=w(x);
This creates a fourth dimensional matrix where the rows change based on the logic, columns are accounted for with k loop, sheets with j loop, and "blocks" with i loop. This may not be the exact setup you're looking for, but it will save the results of Z each time the loop runs.
Alternatively, you can add a new variable that operates the same way, and saves the values of Z into it each loop. This does not have to happen within any particular loop. If you want to only change the sheet (suppose k and j do columns and rows) then you can set the storage variable within the i loop.
for i=1:s
...
storage(:,:,i) = Z;
end

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by