Exclude NaN cells from a cell array

I have a cell array of n number of rows and one column. Each row contains an array.
I want to exclude these NaN cells or copy this cell array in a new one with skipping the NaN cells in the original.

 Respuesta aceptada

Star Strider
Star Strider el 6 de Sept. de 2020
Try this:
fine_xx = {rand(10,1);rand(10,1);[];rand(10,1);[];[];rand(10,1)}
fine_xx = fine_xx(cellfun(@(x)~isempty(x), fine_xx))
That eliminiates the empty [] cells.

2 comentarios

Hazem Al-Bulqini
Hazem Al-Bulqini el 6 de Sept. de 2020
The second line did the job, thank you.
Star Strider
Star Strider el 6 de Sept. de 2020
As always, my pleasure!
(The first line was a test vector I used to be sure my code did what I wanted it to. My apologies for not labeling it as ‘% Test Vector’.)

Iniciar sesión para comentar.

Más respuestas (1)

David Hill
David Hill el 6 de Sept. de 2020
Editada: David Hill el 6 de Sept. de 2020
c=[];
for k=1:length(yourCell)
if ~isempty(yourCell{k})
c=[c,k];
end
end
newCell=yourCell(c);

Categorías

Productos

Etiquetas

Preguntada:

el 6 de Sept. de 2020

Comentada:

el 6 de Sept. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by