MATLAB: Is there a function like string2double that can handle a numerical input

data processingstingstr2num

Hi!
I am importing data that sometimes imports as a string, and sometimes as a number. In all cases I want a number. Is there a function like string2double that can handle a numerical input?
Right now it works like:
>> str2num('2')
ans =
2
>> str2num(2)
Error using str2num (line 35)
Input must be a character vector or string scalar.
Ideally it would work like:
>> FunctionLikestr2num('2')
ans =
2
>> FunctionLikestr2num(2)
ans =
2
Thank you!

Best Answer

First test if the input isnumeric. If it's not, try converting it from text data to a number.