Reduce 3D array by removing NaN elements

8 ビュー (過去 30 日間)
Anthony
Anthony 2014 年 8 月 25 日
回答済み: Anthony 2014 年 8 月 25 日
Hi !
I ask you for help in Matlab in order to reduce a 3D array. In column there is three numbers (X,Y,Z coordinates) and each row corresponds to a different point. But these points have to respect a certain condition, otherwise three NaN are stored instead of the coordinates. The third dimension correspond to the time evolution of the coordinates stored in the 2D array.
For exemple:
A(:,:,1) =
1 2 3
NaN NaN NaN
NaN NaN NaN
A(:,:,2) =
NaN NaN NaN
1 2 3
NaN NaN NaN
A(:,:,3) =
NaN NaN NaN
NaN NaN NaN
NaN NaN NaN
If I try:
A(any(any(isnan(A),3),2),:,:) = [];
I get:
Empty array: 0-by-3-by-3
Or I would have:
A(:,:,1) =
1 2 3
NaN NaN NaN
A(:,:,2) =
NaN NaN NaN
1 2 3
A(:,:,3) =
NaN NaN NaN
NaN NaN NaN
The array is reduced but the shape is the same and I don't lose informations.
Thank your for your help and have a nice day !
  2 件のコメント
the cyclist
the cyclist 2014 年 8 月 25 日
What exactly do you want to get rid of? Any row in which all time slices are NaN?
Anthony
Anthony 2014 年 8 月 25 日
No, in fact my 3D array is very huge (50,000 by 3 by 40). I have to display this array on screen, so there is 2,000,000 lines ! It's very huge and it takes a long time to display so many lines. I just want to reduce this 3D array by removing as many "NaN-lines" as I can without erease "coordinates-lines", unlike to the command:
A(any(any(isnan(A),3),2),:,:) = [];

サインインしてコメントする。

採用された回答

the cyclist
the cyclist 2014 年 8 月 25 日
編集済み: the cyclist 2014 年 8 月 25 日
Maybe you meant all() instead of any()?
idxToRemove = all(all(isnan(A),3),2);
A(idxToRemove,:,:) = []

その他の回答 (1 件)

Anthony
Anthony 2014 年 8 月 25 日
It works perfectly ! Thank you very much ! Could you explain to me how this command works please ? I would understand and not just apply without thinking.

Community Treasure Hunt

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

Start Hunting!

Translated by