Replace String with a NaN in table
Show older comments
Hey guys!
I am challenged with a table, consisting various numbers and a few "'Bad'" cells. I guess they are strings. My goal now is to replace these "Bads" with NaNs.
How do I achieve that the easiest way?
Best regards, Spacey
1 Comment
per isakson
on 24 Mar 2015
"table"   is that
Accepted Answer
More Answers (3)
Konstantinos Sofos
on 24 Mar 2015
Edited: Konstantinos Sofos
on 24 Mar 2015
Hi,
" I guess they are strings" ...you cannot open your table or see in the workspace what type are they?
Do you mean something like the following:
>> A = {'xx',5,6,'''',78,'?..'}
A =
'xx' [5] [6] ''' [78] '?..'
>> idx = cellfun(@(x) ischar(x),A)
idx =
1 0 0 1 0 1
>> A(idx)={NaN}
A =
[NaN] [5] [6] [NaN] [78] [NaN]
>> B = cell2mat(A)
B =
NaN 5 6 NaN 78 NaN
>> whos
Name Size Bytes Class Attributes
A 1x6 408 cell
B 1x6 48 double
Jos (10584)
on 24 Mar 2015
1 vote
Take a look at CELL2FLOAT
Spacey
on 24 Mar 2015
0 votes
Categories
Find more on Characters and Strings in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!