フィルターのクリア

4-d arrays not filling the loop output properly

1 回表示 (過去 30 日間)
Sagar Parajuli
Sagar Parajuli 2021 年 8 月 12 日
コメント済み: Walter Roberson 2021 年 8 月 13 日
I am trying to create a 4-d matrix by extracting data from a 3-d array within a loop. But the results are not as expected. I expect to fill the aod_nonan(:, :, :, 1) with aod_final_arng(:, :, 1:160) and aod_nonan(:, :, :, 2) with aod_final_arng(:, :, 161:320) but both are filled with the second set of results only. I am sure there is a problem here which I can't figure out. Could anyone help please? I have attached sample data.
load aod_final_arng;
for i = 1:2;
for k = 1:160:320;
aod_nonan(:, :, :, i) = aod_final_arng(:, :, k:(k-1)+160);
end;
end;

採用された回答

Walter Roberson
Walter Roberson 2021 年 8 月 12 日
You do not need the loop.
asz = size(aod_final_arng);
aod_nonan = reshape(aod_final_arng, asz(1), asz(2), 160, []);
  4 件のコメント
Sagar Parajuli
Sagar Parajuli 2021 年 8 月 13 日
Thank you, this is perfect, exactly what I was looking for, k_vals should be kvals though. Thank you for explaining.
Walter Roberson
Walter Roberson 2021 年 8 月 13 日
You are right, I mis-typed.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by