"Oscar " <obylund@yahoo.se> wrote in message <ib98el$q21$1@fred.mathworks.com>...
> Hi, I have a problem with vectors and loops
>
> Z=[z1;z2;z3;O]
>
> where z1,z2,z3 and O are individual 201x1 matrices
> our teacher told us to use loops to define Z, here's the code that's apparently wrong, and i'd appreciate it if you could help me with it:
>
> for n=1:201;
> Z(n)=[z1(n,1) z2(n,1) z3(n,1) O(n,1)];
> end
>
> When i run it it says:
>
> ??? In an assignment A(I) = B, the number of elements in B and
> I must be the same.
>
> What am I doing wrong?
> Thanks
you're trying to fit a 1x4 vector ([z1(n,1) z2(n,1) z3(n,1) O(n,1)]) in a 1x1 spot (Z(n))
Try this:
Z = zeros(length(z1),4); %preallocate
for n = 1:length(Z)
Z(N,:) = [z1(n,1) z2(n,1) z3(n,1) O(n,1)]; %all 4 columns in the nth row
end
