NaN from str2double('1 2 3') on Matlab 2020a

조회 수: 4 (최근 30일)
Dawid Strzelczyk
Dawid Strzelczyk 2020년 10월 16일
댓글: James Tursa 2020년 10월 16일
Hi
str2double('1 2 3') returns NaN on Matlab 2020a but works fine on Matlab 2018b & Matlab 2016b (returns: 1 2 3).
How to convert a string of numbers to numbers in the newest Matlab version?
Best,
Dawid
  댓글 수: 1
Stephen23
Stephen23 2020년 10월 16일
For all MATLAB versions the most efficient soluton is:
str = '1 2 3';
vec = sscanf(str,'%f')
Avoid str2num, it contains a hidden eval call...

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

채택된 답변

Bruno Luong
Bruno Luong 2020년 10월 16일
편집: Bruno Luong 2020년 10월 16일
"works fine on Matlab 2018b"
Are you sure?
>> version
ans =
'9.5.0.1298439 (R2018b) Update 7'
>> str2double('1 2 3')
ans =
NaN
>> str2num('1 2 3')
ans =
1 2 3
>>
  댓글 수: 4
Bruno Luong
Bruno Luong 2020년 10월 16일
AFAIK str2double never works on string with multiple numbers.
James Tursa
James Tursa 2020년 10월 16일
One more data point, PCWIN:
>> version
ans =
'9.5.0.944444 (R2018b)'
>> str2double('1 2 3')
ans =
NaN
>> str2num('1 2 3')
ans =
1 2 3

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by