create a new 4D Array from 2 others
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Pepe Grillo
am 24 Feb. 2021
Kommentiert: Pepe Grillo
am 25 Feb. 2021
Hi!
i want to build a new 4d array from 2 others and one array is telling me the position of the values that i want,
any idea?
Thanks!
7 Kommentare
Akzeptierte Antwort
Rik
am 25 Feb. 2021
I think I understand what you mean. The code below will overwrite all values that are not NaN for a given depth, which is equivalent to setting it to the last non-NaN (except if the first value is NaN).
%generate some fake data
%cumsum will ensure all values after the first NaN are NaN as well
u1=rand(241,97,7,1637);u1(u1<0.1)=NaN;u1=cumsum(u1,3);
u2=u1(:,:,1,:);
for depth=1:size(u1,3)
layer=u1(:,:,depth,:);
L=~isnan(layer);
u2(L)=layer(L);
end
3 Kommentare
Rik
am 25 Feb. 2021
That first line was only meant to generate random data. You should replace it with your actual data.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Structures finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!