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?
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});
Error using str2num (line 33) Requires string or character array input.{'[-1, 0, 1, 0, 0, 0]'}? In that case, use x = str2num(c{1})