Filter löschen
Filter löschen

4-d arrays not filling the loop output properly

1 Ansicht (letzte 30 Tage)
Sagar Parajuli
Sagar Parajuli am 12 Aug. 2021
Kommentiert: Walter Roberson am 13 Aug. 2021
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;

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 12 Aug. 2021
You do not need the loop.
asz = size(aod_final_arng);
aod_nonan = reshape(aod_final_arng, asz(1), asz(2), 160, []);
  4 Kommentare
Sagar Parajuli
Sagar Parajuli am 13 Aug. 2021
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 am 13 Aug. 2021
You are right, I mis-typed.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by