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?
You need to remove the characters before using mod function. You can useregexp to remove all non digits characters.
The following code uses regexp to match digits only in variablet , with the expression'\d' . The indices returned by regexp functions are used to get the digit values, before converting them to a number withnum2str.
Best Answer