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

3 ビュー (過去 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 Center および File ExchangeData Type Conversion についてさらに検索

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by