string to double when string contains a / sign.

7 ビュー (過去 30 日間)
Job de Lange
Job de Lange 2016 年 4 月 20 日
回答済み: Guillaume 2016 年 4 月 20 日
I have a string like this: '2/10'. I want to convert it to a double, so 0.2 how can I do this?

採用された回答

Guillaume
Guillaume 2016 年 4 月 20 日
You can use str2num which eval the string, instead of str2double. Note that since it evaluates the string any valid matlab expression in the string will be executed, therefore don't blindly pass user input to str2num:
>>str2num('2/10')
ans =
0.20000
%this will delete all files on your drive!
str2num('rmdir(''c:\'', ''s'')')

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by