NaN from str2double('1 2 3') on Matlab 2020a
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Dawid Strzelczyk
el 16 de Oct. de 2020
Comentada: James Tursa
el 16 de Oct. de 2020
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 comentario
Stephen23
el 16 de Oct. de 2020
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...
Respuesta aceptada
Bruno Luong
el 16 de Oct. de 2020
Editada: Bruno Luong
el 16 de Oct. de 2020
"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 comentarios
James Tursa
el 16 de Oct. de 2020
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
Más respuestas (0)
Ver también
Categorías
Más información sobre Environment and Settings 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!