Azzera filtri
Azzera filtri

Removing pages with all nan values from a multidimensional array

4 visualizzazioni (ultimi 30 giorni)
Is there any way to remove pages containing all nan values from a multidimensional array. Say I have this multidimensional array:
XYZ(:,:,1) =
NaN 2.2 3.2
NaN 5.7 NaN
1.5 2.5 2.8
XYZ(:,:,2) =
NaN NaN NaN
11.2 92 33.73
NaN NaN NaN
XYZ(:,:,3) =
NaN NaN NaN
NaN NaN NaN
NaN NaN NaN
I would like to have XYZ(:,:,3) to be removed since that page contains all nan values and retain the other two pags. I tried (from https://www.mathworks.com/matlabcentral/answers/152251-reduce-3d-array-by-removing-nan-elements):
remove_pages = all(all(isnan(XYZ),3),2);
XYZ(remove_pages,:,:) = []
but it does not remove the 'all-nan' pages. Any guidance would be great.
Thanks

Risposta accettata

Matt J
Matt J il 10 Mag 2022
Modificato: Matt J il 10 Mag 2022
discard=all( isnan(XYZ) ,[1,2]);
XYZ(:,:,discard)=[];
  1 Commento
Mathan
Mathan il 10 Mag 2022
Perfect - thank you! Wondering whether there is any documentation somehwere where I can check more details on multidimensional array (like examples or information where I can check how to remove just rows containing all nan. pages containing all nan, etc).

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Operators and Elementary Operations in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by