# How to convert 'NaN' to numeric NaN

조회 수: 11(최근 30일)
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 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 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'.

댓글을 달려면 로그인하십시오.

### Community Treasure Hunt

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

Start Hunting!

Translated by