Borrar filtros
Borrar filtros

4-d arrays not filling the loop output properly

1 visualización (últimos 30 días)
Sagar Parajuli
Sagar Parajuli el 12 de Ag. de 2021
Comentada: Walter Roberson el 13 de Ag. de 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;

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by