How to store every matrix values that it's element changed in multiple loop
Infos
Cette question est clôturée. Rouvrir pour modifier ou répondre.
Afficher commentaires plus anciens
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
1 commentaire
KSSV
le 7 Août 2018
You have initialized Z already.....to what you want to save?
Réponses (1)
Bob Thompson
le 7 Août 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
Cette question est clôturée.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!