MATLAB: Suppose x=[1 2 3 4 5 6] and y(1)=[1 2],y(2)=[3 4],y(3)=[5 6].how can i take like this in matlab

MATLAB

x=1:6;
j=1:2:6
for i=1:3
for k=1:length(j)
y(i)=[x(k) x(k+1)];
end
end

Best Answer

Try this
x=1:6;
y = reshape(x, 2, [])'
You'll see
y =
1 2
3 4
5 6