How to convert 'NaN' to numeric NaN

8 Ansichten (letzte 30 Tage)
Cordell Knighten
Cordell Knighten am 5 Apr. 2021
I have a 13x5 cell array which contains 4 'NaN' and I need to convert them from 'NaN'(string) to NaN(numeric). I have to use a nested loop as well the strcmp function but I don't know where to start.

Antworten (1)

KALYAN ACHARJYA
KALYAN ACHARJYA am 5 Apr. 2021
Is this?
>> str2num('NaN')
ans =
NaN
Or
data={2,5,NaN,6}
cell2mat(data)
#
data =
1×4 cell array
{[2]} {[5]} {[NaN]} {[6]}
ans =
2 5 NaN 6
  1 Kommentar
Cordell Knighten
Cordell Knighten am 5 Apr. 2021
I tried both them earlier but it doesn't accept either of them. I provided a comment below to be concise. It wanted me to use the compare string function (strcmp) and a nested loop.
%Change the 'NaN' in the materialsData cell array to NaN using a nested
%loop. strcmp(s1,'NaN')can be used to find if s1 is 'NaN'.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by