Q:

MATLAB convert string representing array to actual array?

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?

A:

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});

