3D matrix subtraction

16 ビュー (過去 30 日間)
Thishan Dharshana
Thishan Dharshana 2023 年 2 月 12 日
編集済み: Thishan Dharshana 2023 年 2 月 12 日
I have the following loop. The problem is I cannot get different values for NSSST as i and j changes
clear i j
for i=1:12
for j=1:12:324
NSSST=SST(:,:,j)-SSST(:,:,i);
j=j+1;
end
i=i+1;
end
end

採用された回答

Image Analyst
Image Analyst 2023 年 2 月 12 日
First of all, the clear is not necessary at all. Secondly you don't need to increment i and j because the for loops do that automatically for you. Third, you're not indexing NSSST so you're just overwriting a scalar every iteration. Maybe you want:
for i = 1 : 12
for j = 1 : 12 : 324
NSSST(i, j) = SST(:,:,j) - SSST(:,:,i);
end
end
  2 件のコメント
Torsten
Torsten 2023 年 2 月 12 日
編集済み: Torsten 2023 年 2 月 12 日
But you don't get scalars, but 2d matrices as results from the subtraction ...
Maybe something like
count = 0;
for i = 1 : 12
for j = 1 : 12 : 324
count = count + 1;
NSSST(:,:,count) = SST(:,:,j) - SSST(:,:,i);
end
end
Thishan Dharshana
Thishan Dharshana 2023 年 2 月 12 日
編集済み: Thishan Dharshana 2023 年 2 月 12 日
Thanks a lot. The answer with "count" is what I wanted.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by