Reputation: 17008
I have the following:
ans =
'[-1, 0, 1, 0, 0, 0]'
I really want the variable
x = [-1, 0, 1, 0, 0, 0]
How can I convert ans
into x
?
Upvotes: 1
Views: 274
Reputation: 112769
Use str2num
:
s = '[-1, 0, 1, 0, 0, 0]';
x = str2num(s);
If your input is a cell array:
c = {'[-1, 0, 1, 0, 0, 0]'};
x = str2num(c{1});
Upvotes: 3