Detecting NaN in cell array

129 views (last 30 days)
SG on 26 May 2015
Edited: beginner94 on 18 Dec 2018
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.

Accepted Answer

Walter Roberson
Walter Roberson on 26 May 2015
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)
beginner94 on 18 Dec 2018
Edited: beginner94 on 18 Dec 2018
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!

Sign in to comment.

More Answers (0)


Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by