Comments on: All combinations from vectors https://blogs.mathworks.com/pick/2007/03/02/all-combinations-from-vectors/?s_tid=feedtopost Jiro and Sean share favorite user-contributed submissions from the File Exchange. Tue, 10 May 2016 18:35:27 +0000 hourly 1 https://wordpress.org/?v=6.2.2 By: Zoran Zegarac https://blogs.mathworks.com/pick/2007/03/02/all-combinations-from-vectors/#comment-13942 Mon, 29 Nov 2010 07:50:01 +0000 https://blogs.mathworks.com/pick/2007/03/02/all-combinations-from-vectors/#comment-13942 Yes, Yuri what is pp? I do not know if this would work with my impdance matrix problem. There are 3 varibles, and each can have a value from 1 to 3, and all possible sets of 2 of this variables are: 11 22 33 12 13 21 31 23 32 All in all, 3*3= 9, which is easy to do manually. Now, doing the same as above, but now with 6 variables, each one can have value form 1 to 9, making a total of 9*9*9*9*9*9=531441. Has anybody got and idea, please? Zoran ]]> By: eliza https://blogs.mathworks.com/pick/2007/03/02/all-combinations-from-vectors/#comment-13534 Fri, 23 Apr 2010 03:09:25 +0000 https://blogs.mathworks.com/pick/2007/03/02/all-combinations-from-vectors/#comment-13534 Yury, What is PP?

]]>
By: Yury https://blogs.mathworks.com/pick/2007/03/02/all-combinations-from-vectors/#comment-13485 Thu, 25 Mar 2010 11:42:14 +0000 https://blogs.mathworks.com/pick/2007/03/02/all-combinations-from-vectors/#comment-13485 Let NN=[2 1 2] (each element is number of combinations) and we need matrix of all combinations such as:
1 1 1
1 1 2
2 1 1
2 1 2
Here is solution:

for i=1:prod(NN)
  t=i-1;  
  for j=length(PP):-1:1
    M(i,j)=mod(t,NN(j))+1;
    t = fix(t/NN(j));
  end
end
]]>
By: Doug https://blogs.mathworks.com/pick/2007/03/02/all-combinations-from-vectors/#comment-13439 Thu, 25 Feb 2010 20:57:36 +0000 https://blogs.mathworks.com/pick/2007/03/02/all-combinations-from-vectors/#comment-13439 @Marina,

What you are asking for is not permutation exactly. I am not sure that what you are asking for has a specific name in statistics, so you will have to write your own MATLAB code to solve this.

It should not be too hard. I am assuming none of the N groups that hold M objects is to be empty, and that every object is in a group. If so, you can calculate how many different ways to group things without perms.m

Doug

]]>
By: Marina Zahari https://blogs.mathworks.com/pick/2007/03/02/all-combinations-from-vectors/#comment-13436 Tue, 23 Feb 2010 23:27:02 +0000 https://blogs.mathworks.com/pick/2007/03/02/all-combinations-from-vectors/#comment-13436 I have tried to use perms.m for my problem but it didn’t work. Suppose that we have 4 objects, A, B, C, and D. And I would like to assign them to 3 unique labels/ groupings – 1,2 or 3. So all possible unrepetitve combinations will be:

1 1 2 3 (meaning A and B in group 1, C in group 2 and D in group 3)
1 2 1 3
1 2 3 1
2 1 1 3
2 1 3 1
2 3 1 1.

perms.m gave me the extras,
1 1 3 2, 1 3 1 2, 1 3 2 1, 3 1 1 2, 3 1 2 1 and 3 2 1 1 which I do not need. For example 1 1 3 2 still assign A ann B in group 1.

If you could point me in the right direction, I would greatly appreciate it.

Thank you
Marina

]]>
By: Mithat Perköz https://blogs.mathworks.com/pick/2007/03/02/all-combinations-from-vectors/#comment-13171 Tue, 02 Jun 2009 10:27:54 +0000 https://blogs.mathworks.com/pick/2007/03/02/all-combinations-from-vectors/#comment-13171 Thank you very much, I was just looking for an algorithm like this!

]]>
By: Doug https://blogs.mathworks.com/pick/2007/03/02/all-combinations-from-vectors/#comment-12913 Tue, 28 Oct 2008 17:15:41 +0000 https://blogs.mathworks.com/pick/2007/03/02/all-combinations-from-vectors/#comment-12913 I think you need to look at the problem as such. Each element of the vector can reside in exactly one of three bins.

3 * 3 * 3 * 3 or numBins ^ numElements

-Doug

]]>
By: Amanda https://blogs.mathworks.com/pick/2007/03/02/all-combinations-from-vectors/#comment-12910 Mon, 27 Oct 2008 18:40:40 +0000 https://blogs.mathworks.com/pick/2007/03/02/all-combinations-from-vectors/#comment-12910 Doug,

I’ve been struggling with a matlab problem of combinations and permutations for a while and came across your post here. I thought you might be able to help me out.

Let’s say I have a vector say A =[1 2 3 4] and want to find every way I can choose all the elements of A to fit in some number of bins (let’s say 3). Bin 1 could have (1, 2, 3), Bin 2 could have (4) or (0) and Bin 3 could have (4) or (0) as well. The problem isn’t quite solved by “nchoosek” because each bin could have more or less elements than the previous bin and the element choice for each bin depends on the elements not already chosen. I know that the number of possible combinations is # of elements in A^#of bins (in this case 81), because I solved it out by hand. I am looking for an easier way! I’m sorry if this sounds confusing!

If you can point me in the right direction or offer me any help I would greatly appreciate it!

Thank you,

Amanda Palazzo

]]>