MATLAB: How to execute str2num or str2double in matlab

str2doublestr2num

I am having trouble using commands str2num.
I have a character
t='2'
'u1'
'u2 '
I used the command p=str2double(char(t)). Right now if I use str2num, a null array appears in the output whereas using str2double gives NaN in output. While searching about these I learned that these character values are not converted to numbers.
I wanted p to store values [2, 1, 2]. How can I do that? Thanks for reading…

Best Answer

Simple, and possibly the most efficient way:
>> t = {'2','u1','u2 '};
>> sscanf([t{:}],'%du')
ans =
2
1
2