Clear Filters
Clear Filters

4-d arrays not filling the loop output properly

1 view (last 30 days)
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;

Accepted Answer

Walter Roberson
Walter Roberson on 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 Comments
Sagar Parajuli
Sagar Parajuli on 13 Aug 2021
Thank you, this is perfect, exactly what I was looking for, k_vals should be kvals though. Thank you for explaining.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!