Matlab, combinations of all cells -
this question has answer here:
i need combine data of n (random) arrays different lengths. ex: a=[1 3 2 7 8], b=[2 5 3 9] , c=[5 6] , maybe have d, e, f etc.... need combination of elements like: m={[1 2 5], [1 2 6], [1 5 5], [1 5 6], [1 3 5], [1 3 6] ....}.
solution 3 arrays:
[a,b,c] = meshgrid(a, b, c); m = [a(:), b(:), c(:)];
solution n arrays iterating on short dimension n:
a=[1 3 2 7 8]; b=[2 5 3 9]; c=[5 6]; d=[1 3 5]; arrays = { a, b, c, d }; m = a'; = 2:length(arrays) a1 = m; a2 = arrays{i}'; [i1, i2] = meshgrid(1:length(a1), 1:length(a2)); m = [a1(i1(:), :) a2(i2(:))]; end
Comments
Post a Comment