Borrar filtros
Borrar filtros

Remove NaN from cell array

3 visualizaciones (últimos 30 días)
Laila Rezai
Laila Rezai el 7 de Sept. de 2019
Comentada: Laila Rezai el 7 de Sept. de 2019
Hi,
I want to remove cell with NaN input from a cell array. The cell array itself is a field of a structure and the structue is nested inside another cell array of (16x1).
The name of explained cell array with NaN input in my code is y_fast{i,1}.OutList. I write this command to remove NaN from it:
for i=1:length(y_fast)
y_fast{i,1}.OutList(cellfun(@(x)any(isnan(x)),y_fast{i,1}.OutList)) = [];
end
it is run without any error but it does not remove the NaN from the cell array.
why?? Could Someone help me??

Respuesta aceptada

madhan ravi
madhan ravi el 7 de Sept. de 2019
Editada: madhan ravi el 7 de Sept. de 2019
S=[y_fast{:}];
ix=cellfun(@(x)any(isnan(x.OutList)),y_fast);
y_fast(ix)=arrayfun(@(x)rmfield(x,'OutList'),S(ix),'un',0)
  3 comentarios
madhan ravi
madhan ravi el 7 de Sept. de 2019
for k=1:numel(y_fast)
y_fast{k}.OutList=y_fast{k}.OutList(~strcmp(y_fast{k}.OutList,'NaN'))
end
Laila Rezai
Laila Rezai el 7 de Sept. de 2019
Thanks alot!!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre String Parsing 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