# how to generate combination through specific matrix dimension?

1 回表示 (過去 30 日間)
Amirah 2018 年 2 月 22 日

I have a matrix (128, 128, 20, 8) the 4th diminution is 4 pairs; how can I generate a combination of that 4th diminution as 4-pairs by picking 2 each time?
##### 2 件のコメントなしを表示なしを非表示
James Tursa 2018 年 2 月 22 日
Your question is not clear. Is this an indexing question, or a random selection question, or ...? Please provide a short example clearly showing desired output.
Amirah 2018 年 2 月 24 日
Dear James I have images in 4D matrix (128, 128, 20, 8); 8 represent the image repetitions where 1:2 is the 1st pair (control and label), 3:4 2ed repetition and so on I want to create the possible combinations of these pairs without repetition; the possible combinations, in this case, is 1st pair with 2ed pair; 1st pair with 3ed pair; 1st pair with 4th pair; 2 3, 2 4 and 3 4 and then to calculate the dif of each pair divided by their mean 1 2; 1 3; 1 4; 2 3; 2 4; 3 4; then (1-2)/((1+2)/2) I tried to transform the matrix into cell array where each cell contains one pair, but then I struggling to produce their combinator which is the step before calculation thank you Amirah

サインインしてコメントする。

### 回答 (2 件)

Roger Stafford 2018 年 2 月 23 日
As James has stated, your question is not clear. I'm going to make a very wild guess as to your meaning. If it is wrong, as is likely, perhaps the method I show will give you some ideas of how you can achieve what you actually want.
Let your original 128x128x20x8 matrix be called A. Let the matrix you want to create be called B. I will suppose that your pairings in the 4th dimension of A are 1 and 2, 3 and 4, 5 and 6, 7 and 8. You then want to take all possible combinations of two pairs out of these four: 1,2,3,4 then 1,2,5,6 then 1,2,7,8, then 3,4,5,6 and so forth. This will give you a size of 4*6 = 24 at the fourth dimension.
C = nchoosek(1:2:7,2); % Choose 2 out of 4
n = size(C,1); % n = 4!/2!/2! = 6 in this case
B = repmat(zeros(size(A)),1,1,1,n/2); % B will have size 8*6/2=24 at 4th dimension
for ix = 1:n
B(:,:,:,4*ix-3:4*ix) = A(:,:,:,[C(ix,1),C(ix,1)+1,C(ix,2),C(ix,2)+1]);
end
##### 0 件のコメント-2 件の古いコメントを表示-2 件の古いコメントを非表示

サインインしてコメントする。

Amirah 2018 年 2 月 26 日
I have images in 4D matrix (128, 128, 20, 8); 8 represent the image repetitions where 1:2 is the 1st pair (control and label), 3:4 2ed repetition and so on I want to create the possible combinations of these pairs without repetition; the possible combinations, in this case, is 1st pair with 2ed pair; 1st pair with 3ed pair; 1st pair with 4th pair; 2 3, 2 4 and 3 4 and then to calculate the dif of each pair divided by their mean 1 2; 1 3; 1 4; 2 3; 2 4; 3 4; then (1-2)/((1+2)/2) I tried to transform the matrix into cell array where each cell contains one pair, but then I struggling to produce their combinator which is the step before calculation thank you Amirah

サインインしてコメントする。

### カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by