How to convert 'NaN' to numeric NaN

10 visualizaciones (últimos 30 días)
Cordell Knighten
Cordell Knighten el 5 de Abr. de 2021
Comentada: Cordell Knighten el 5 de Abr. de 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.

Respuestas (1)

KALYAN ACHARJYA
KALYAN ACHARJYA el 5 de Abr. de 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 comentario
Cordell Knighten
Cordell Knighten el 5 de Abr. de 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'.

Iniciar sesión para comentar.

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by