How to convert 'NaN' to numeric NaN

10 vues (au cours des 30 derniers jours)
Cordell Knighten
Cordell Knighten le 5 Avr 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.

Réponses (1)

KALYAN ACHARJYA
KALYAN ACHARJYA le 5 Avr 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 commentaire
Cordell Knighten
Cordell Knighten le 5 Avr 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'.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by