MATLAB: How to code in a neat way

code generation

Is there a way to code in a different way instead of repeating it for that many times? Below are an example of my code. y is an array 20 x 10000. I will need to do data analysis individually later, e.g. X1 for data analysis, X2, X3, etc. Thank you.
segLength = 10
X1 = reshape(y(1,:),segLength, [])';
X2 = reshape(y(2,:),segLength, [])';
X3 = reshape(y(3,:),segLength, [])';
X4 = reshape(y(4,:),segLength, [])';
X5 = reshape(y(5,:),segLength, [])';
% X6......X19
X20 = reshape(y(20,:),segLength, [])';

Best Answer

No. If you are going to use numbered variables like that then you should expect to write them all out and to always have the same number of them.
The better approach is to not use numbered variables. For example you could use arrayfun with uniform false and emit a cell array. Or better yet
reshape(y.', segLength, [], size(y, 1))