How to store every matrix values that it's element changed in multiple loop
情報
この質問は閉じられています。 編集または回答するには再度開いてください。
古いコメントを表示
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 件のコメント
KSSV
2018 年 8 月 7 日
You have initialized Z already.....to what you want to save?
回答 (1 件)
Bob Thompson
2018 年 8 月 7 日
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 件のコメント
この質問は閉じられています。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!