Combination calculations and matrix manipulation
1 回表示 (過去 30 日間)
古いコメントを表示
Hello, I am working on a matrix (m x n) and I want to pick up different groups of m elements which have to be non dependent. Practically speaking I need (n-1)*m+2. For n = 4 and m = 3 I need 11 groups and an example of matrix is: [1 2 3 4, 5 6 7 8, 9 10 11 12] and the groups might be
(1 5 9),(1 5 10),(1 5 11),(1 5 12) 4
(1 6 9),(1 7 9),(1 8 9) 3
(2 5 9),(3 5 9),(4 5 9) 3
(2 6 9) 1
I have the matrix written, do you have any suggestion how to write this problem assuming that n and m are completely random and the first group has to be composed by the first column.
Thank you very much Antonio
0 件のコメント
採用された回答
Matt Fig
2011 年 5 月 14 日
A = [1 2 3 4;
5 6 7 8;
9 10 11 12];
[m,n] = size(A);
I = npermutek(1:n,m);
J = cumsum(ones(size(I)),2);
R = A(J+(I-1)*m) % Look at each row.
If you find that NPERMUTEK gives you too many samplings, you could try one of the lesser combinatorial samplings found in this file: COMBINATOR
その他の回答 (3 件)
mortain Antonio
2011 年 5 月 14 日
1 件のコメント
Matt Fig
2011 年 5 月 14 日
Your first approach using COMBINATOR is NOT what I recommended. Use the output from COMBINATOR the same way I used NPERMUTEK in my first post.
Your second attempt is very odd, since NPERMUTEK is not a recursive algorithm. Did you make changes to the code before you got that error? Because when I copy and paste your code I get R = 64-by-3 where each row has one pick for each row of A, EXACTLY the same as Andrei's code below.
Andrei Bobrov
2011 年 5 月 14 日
more so?
A = [1 2 3 4;
5 6 7 8;
9 10 11 12];
A1 = mat2cell(A,[1 1 1],size(A,2));
[J K I] = meshgrid(A1{[2 3 1]});
R = [I(:) J(:) K(:)];
0 件のコメント
mortain Antonio
2011 年 5 月 16 日
3 件のコメント
Oleg Komarov
2011 年 5 月 16 日
Goog example how to AVOID vectorization on MatLab (Matrix Laboratory) - LOLZ
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!