You don't need a loop if you use reshape
:
cols = [1:3];
z1 = reshape(U(:,cols), numel(U(:,cols)), 1);
You can also use this for non-consecutive columns, for example:
cols = [1 2 4 7];
Example:
A = [1 2 3;
4 5 6;
7 8 9]
cols = [1:2];
B = reshape(A(:,cols), numel(A(:,cols)), 1)
The output is:
A =
1 2 3
4 5 6
7 8 9
B =
1
4
7
2
5
8