필터 지우기
필터 지우기

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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by