MATLAB: String that may or may not need to be converted to num…

str2doublestr2num

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!

Best Answer

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.