MATLAB: Slicing matrix in efficient way

indexMATLABmatrixslicing

I have a 120*1 matrix and i want to divide into 3 matrix x,y,z where first 10 elements goes to x, next 10 to y and next 10 to z and then next 10 elements to x as the second column. I did that
x = [1:10; 31:40; 61:70; 91:100] %=[10x4]

y = [11:20;41:50;71:80;101:.110] % =[10x4]
z= [21:30; 51:60; 81:90;111:120] %=[10x4]
Is there any efficient way to do that?

Best Answer

Something like this should do the trick:
a=1:120;
b=reshape(a,10,3,[]);
x=squeeze(b(:,1,:));
y=squeeze(b(:,2,:));
z=squeeze(b(:,3,:));