MATLAB: Split vector by parts with more evenly distributed length

splitsplit_by_partssubarraysubvector

While my previous question got answered fine (and I did not specify it good enough), I'm looking for a way to split a vector so that the sizes of the subvectors are more evenly distributed. Let me explain with the following example.
So again let's say I have the following vector
V = 1:2184
P = [floor(length(V/127)) & ceil(length(V/127))] %[17 18]
Now I want to split the vector somewhat more distributed, so:
sv1 sv2 sv3 sv4 sv5 ... sv123 sv124 sv125 sv126 sv127 %subvector;
Vbad = [17 17 17 17 17 ... 17 20] %sv length; don't want this
Vgood = [17 17 17 17 17 ... 17 17 18 18 18] %sv length; looking for this; always end up with 127 subvectors
Thanks in advance.

Best Answer

As @dbp pointed out, the problem still isn't well defined, but based on your example the answer will only contain P or P+1 elements.
V = 1:2184;
numberPartition = 127;
P = floor(length(V)/numberPartition);
L = length(V) - numberPartition*P;
partitionElements = [P*ones(1, numberPartition-L) (P+1)*ones(1, L)];
partitions = mat2cell(V, 1, partitionElements);