필터 지우기
필터 지우기

How to remove Nan layers from 3D array?

조회 수: 1 (최근 30일)
Giacomo Caporusso
Giacomo Caporusso 2023년 7월 10일
댓글: Giacomo Caporusso 2023년 7월 13일
I have an array of 3 dimensions (rows, columns end layers).
I want to do two things:
1) get the list of layers containing only nan;
3) get the array where the layers containing only nan have been removed.

채택된 답변

Deep
Deep 2023년 7월 10일
Here's a short demo on this:
% A is your 3D array
A = rand(4,4,4);
A(:,:,2) = nan; % making second layer nan for demonstration
% Check if a layer contains only NaN
layersWithNaN = all(all(isnan(A), 1), 2);
% 1. Get the list of layers containing only NaN
listOfLayersWithNaN = find(layersWithNaN);
% 2. Get the array where the layers containing only NaN have been removed
A(:,:,listOfLayersWithNaN) = [];
  댓글 수: 1
Giacomo Caporusso
Giacomo Caporusso 2023년 7월 13일
Thank you so much.
The instructions work perfectly.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by