From: Shar on
Dear all,
I am struggling to come up with an efficient decomposition of a vector into contigious, non-overlapping segments.
[1 5 6] = . 1;5;6 . 1 5; 6 . 1; 5 6
is there an efficient, quantized way to do it?
I would be very grateful for your help.
Shar
From: Bruno Luong on
You might use allVL1 tool on FEX:
http://www.mathworks.com/matlabcentral/fileexchange/17818-all-permutations-of-integers-with-sum-criteria

a = [1 5 6];

n = size(a,2);
c = [];
for k=1:n
m = allVL1(k,n-k)+1;
ck = arrayfun(@(i) mat2cell(a, 1, m(i,:)), 1:size(m,1), 'Uni', false);
c = [c ck];
end

% Each element of C is a ordered partition of a
c{:}

Note: This problem is related to the so called "integer partition" problem, where a lot of imminent mathematicians are working on.

Bruno
From: Shar on
Thank you, Bruno, the tool works perfectly!
Best regards,
Shar T.