From: Shar on 25 May 2010 03:55 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 25 May 2010 04:48 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 25 May 2010 05:56 Thank you, Bruno, the tool works perfectly! Best regards, Shar T.
|
Pages: 1 Prev: Wrong results in Pdepe .m file for heat transfer in cylinder...HELP Next: N-gram extraction |