MATLAB: Cut vector into many new vectors with defined lengths

cut vectorreduce vectorresize vector

I have a very long vector that I would like to cut up into new vectors of a specified length (400).

Best Answer

The easiest way to do what you want would be to use the mat2cell command. For instance, if you wanted to divide it into segments of lengths of [100, 150, 50, 25, 75]:
V = randi(99, 1, 400);
Vs = mat2cell(V, 1, [100, 150, 50, 25, 75]);
Vs4 = Vs{4}; % Addressing Cell #4
Here, ‘Vs’ is a (1x5) cell, and ‘Vs4’ is a (1x25) double.