How to convert 'NaN' to numeric NaN

9 ビュー (過去 30 日間)
Cordell Knighten
Cordell Knighten 2021 年 4 月 5 日
コメント済み: Cordell Knighten 2021 年 4 月 5 日
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.

回答 (1 件)

KALYAN ACHARJYA
KALYAN ACHARJYA 2021 年 4 月 5 日
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 件のコメント
Cordell Knighten
Cordell Knighten 2021 年 4 月 5 日
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'.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by