string to double when string contains a / sign.
7 次查看(过去 30 天)
显示 更早的评论
I have a string like this: '2/10'. I want to convert it to a double, so 0.2 how can I do this?
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!