Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Avoid combination between elements from the same category

조회 수: 2 (최근 30일)
Rachel Sabioni
Rachel Sabioni 2019년 3월 19일
마감: MATLAB Answer Bot 2021년 8월 20일
Dears,
I would like to combine elements from a matrix. These elements are categorized and elements from the same category cannot be combined.
Modules = ({'M1'; 'M1'; 'M1'; 'M2'; 'M2'}) %Matrix with my categories
MI = ({'A'; 'B';'C';'D';'E'}) %Matrix with my elements
B = nchoosek(MI, 2)
T =
5×2 table
Modules MI
_______ ______________________
'M1' 'A'
'M1' 'B'
'M1' 'C'
'M2' 'D'
'M2' 'E'
Table T shows in which categoy of module each MI is comprised.
I want to create a matrix B in which I will combine 2 elements by row, excluding all combinations of elements from the same category of module.
Could you help me ?
Thanks in advance,

답변 (1개)

Walter Roberson
Walter Roberson 2019년 3월 19일
[P,Q] = ndgrid({'A', 'B', 'C'}, {'D', 'E'});
[P(:), Q(:)]
  댓글 수: 1
Rachel Sabioni
Rachel Sabioni 2019년 3월 20일
Dear Mr. Walter,
It worked very well. Thank you so much for your help !
Rachel

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by