Why is str2num returning [] and str2double returning NaN?

I am new to Matlab and am having a hard ime figuring out how to turn a string into a number.
I have a line of text data that shows up as a cell, and I was able to convert that into a string. Then I created a new by extracting a specific part of the previous string. The specific part of the original string that I extracted is a single number. I want to turn it into a number so that I am able to use it to do a conversion.
This is what I have in my script:
v = A.textdata(5,:)
str = char(v)
newStr1 = extractBetween(char(v),'Accel sens, ',',counts/g')
newStr2 = extractBetween(char(v),'Mag sens, ',',counts/mT')
X = str2double('newStr1')
Y = str2doule('newStr2')
This is what is returned when I test the code:
(Y is cut off but it returned NaN)

 Respuesta aceptada

dpb
dpb el 6 de Mayo de 2019
X = str2double('newStr1')
Y = str2doule('newStr2')
You're trying to turn the literal character arrays 'newStr1' and 'newStr2' into numbers which, while they have an embedded numeric character aren't recognizable as numbers.
You intended to use the variables instead--
X = str2double(newStr1)
Y = str2doule(newStr2)

Más respuestas (0)

Categorías

Más información sobre Data Type Conversion en Centro de ayuda y File Exchange.

Preguntada:

el 6 de Mayo de 2019

Comentada:

el 6 de Mayo de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by