string that may or may not need to be converted to num...
1 次查看(过去 30 天)
显示 更早的评论
I am bringing a string into a function. I need to convert it to num ONLY if it's intended as a number like 2, 40, 100... but when the user enters it as something else, leave it as a string. Can that be done?
Thanks!
0 个评论
采纳的回答
Bish Erbas
2018-9-24
编辑:Bish Erbas
2018-9-24
Yes. Take a look at the function below:
str2num
Edit: OP clarified their question and one way to accomplish what they need would be using the following function:
Edit2: Use str2double instead. See comments section for details.
5 个评论
Bish Erbas
2018-9-24
@Stephen Cobeldick is absolutely right. Thanks for the helpful reminder. Old habits die hard. I gotta learn to remember using the more efficient str2double
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!