Detecting NaN in cell array

조회 수: 75 (최근 30일)
SG
SG 2015년 5월 26일
편집: beginner94 2018년 12월 18일
I have a 54x8 cell array that contains only strings. Most of these strings represent numbers and I would like to detect which cells are NaN.
One possibility would simply be to replace all NaN with ' ' or to check whether each d{i,j} == NaN.
Thanks

채택된 답변

Walter Roberson
Walter Roberson 2015년 5월 26일
cellfun(@(C) any(isnan(C(:)), YourCell)
However in your situation you could probably go with
cellfun(@isnumeric, C)
Oh wait, when you say NaN, do you mean the string 'NaN' ? If so then
cellfun(@(C) strcmp(C, 'NaN'), C)
  댓글 수: 6
Walter Roberson
Walter Roberson 2017년 7월 8일
G H are you comparing numeric nan or string 'NaN'
beginner94
beginner94 2018년 12월 18일
편집: beginner94 2018년 12월 18일
Hello,
@WalterRoberson:
Is there a way to use this
cellfun(@(ds) strcmp(ds, 'NaN'), ds))
when the cell elements are not aligned but below each other?
Thank you!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by