Here is a test, please try it. I can't explain the reason. Thanks.
>> a='sss'
a =
'sss'
>> b=str2num(a)
b =
[]
>> isnumeric(b)
ans =
logical
1
>> a='ss'
a =
'ss'
>> b=str2num(a)
b =
Empty state-space model.
>> isnumeric(b)
ans =
logical
0
>> a='ssa'
a =
'ssa'
>> b=str2num(a)
b =
[]
>> isnumeric(b)
ans =
logical
1
>>

1 件のコメント

Geoff Hayes
Geoff Hayes 2020 年 2 月 5 日
John - I saw this link Create state-space model, convert to state-space model which may be relevant given the 'ss' string and the 'Empty state-space model' message. Perhaps, under the hood, MATLAB is taking the 'ss' string and somehow creating a state space model (since ss is the function used to create a state space model).

サインインしてコメントする。

回答 (3 件)

Fangjun Jiang
Fangjun Jiang 2020 年 2 月 5 日

0 投票

ss() happen to be a function. You could run b=ss alone;
Steven Lord
Steven Lord 2020 年 2 月 5 日

0 投票

From the documentation page for str2num: "In addition, str2num uses the eval function, which can cause unintended side effects when the input includes a function name. To avoid these issues, use str2double."
Neither sss nor ssa are functions in any MathWorks product.
ss is a function in Control System Toolbox.
John
John 2020 年 2 月 5 日

0 投票

Sometimes str2double gives error. Anyways, either way, How can we test if the input string is numeric? Like this:
>> a='notnumeric'
a =
'notnumeric'
>> b=str2double(a)
b =
NaN
>> isnumeric(b)
ans =
logical
1
The test says it's a numeric.

カテゴリ

ヘルプ センター および File ExchangeData Type Conversion についてさらに検索

質問済み:

2020 年 2 月 5 日

回答済み:

2020 年 2 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by