Removing pages with all nan values from a multidimensional array
3 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!