Borrar filtros
Borrar filtros

How to remove Nan layers from 3D array?

5 visualizaciones (últimos 30 días)
Giacomo Caporusso
Giacomo Caporusso el 10 de Jul. de 2023
Comentada: Giacomo Caporusso el 13 de Jul. de 2023
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.

Respuesta aceptada

Deep
Deep el 10 de Jul. de 2023
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 comentario
Giacomo Caporusso
Giacomo Caporusso el 13 de Jul. de 2023
Thank you so much.
The instructions work perfectly.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Operators and Elementary Operations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by