MATLAB: Questions on assigning values from a vector

indexingvectors

Hi all,
I am trying to do this assignment:
x1=x(1);
x2=x(2);
.
.
xN=x(N);
How could I do it using a for loop so that I don't need to write them down explicitly. Thanks.

Best Answer

x = randn(10,1);
for nn = 1:10
eval(['x' int2str(nn),' = x(nn);']);
end
But eval() is pretty inefficient, so are you sure you want to do this. Anyway, you'll see that if you execute the above you will have variables x1, x2, ... x10 in your workspace