Info
This question is closed. Reopen it to edit or answer.
How to store every matrix values that it's element changed in multiple loop
1 view (last 30 days)
Show older comments
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 Comment
Answers (1)
Bob Thompson
on 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
0 Comments
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!