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??

 채택된 답변

madhan ravi
madhan ravi 2019년 9월 7일
편집: madhan ravi 2019년 9월 7일

0 개 추천

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

Laila Rezai
Laila Rezai 2019년 9월 7일
good answer but it give me back the following error:
Error using horzcat
Number of fields in structure arrays being concatenated do not match.
Concatenation of structure arrays requires that these arrays have the same set
of fields.
I attach y_fast.mat data here. I had to reduce the size of y_fast from 16x1 cell to 1x1 cell, because of attachment size limitation, but the all removed cells have the same structure.
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 2019년 9월 7일
Thanks alot!!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

태그

질문:

2019년 9월 7일

댓글:

2019년 9월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by