Why is str2num returning [] and str2double returning NaN?

10 ビュー (過去 30 日間)
Grace
Grace 2019 年 5 月 6 日
コメント済み: Grace 2019 年 5 月 6 日
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)

採用された回答

dpb
dpb 2019 年 5 月 6 日
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)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by