필터 지우기
필터 지우기

How can I generate all possible combinations of a matrix which have a certain value?

조회 수: 1 (최근 30일)
How can matlab provide all possible combinations of a matrix which equals to zero? For example: I have the matrix a=[0 1 0; 1 1 0; 0 1 1] and matlab has to give the answer: 1 3 7 8, 1 3 7, 1 3 8, 1 7 8, 3 7 8, 1 3, 1 7, 1 8, 3 7, 3 8, 7 8.

채택된 답변

Andrei Bobrov
Andrei Bobrov 2014년 10월 20일
n = find(a==0);
out = arrayfun(@(x)nchoosek(n,x),numel(n):-1:2,'un',0)
  댓글 수: 2
Guillaume
Guillaume 2014년 10월 20일
For people unfamiliar with arrayfun, the 'un', 0 at the end is short for 'UniformOutput', false, which means put the output in a cell array.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by