Hi My question is how to pick up elements from data. if each element can be chosen or not, it will be 2^n. suppose we have 3 elements ,2^3 types can be picked . n element in 2^n.what's the command of this format?

댓글 수: 2

Geoff Hayes
Geoff Hayes 2015년 1월 26일
Soosan - please provide a simple example of what you expect. If n is three, what are the 8 types?
adele
adele 2015년 1월 26일
편집: adele 2015년 1월 26일
n=1 2 3 combination: 0
1
2
3
1,2
1,3
2,3
1,2,3

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

 채택된 답변

Thorsten
Thorsten 2015년 1월 26일
편집: Thorsten 2015년 1월 26일

0 개 추천

To compute a cellarray 'combinations' with all 2^N possible combinations of elements, you can use:
val = 1:3;
N = numel(val);
binind = dec2bin( [0 1:2^N - 1]);
for i = 1:2^N
combinations{i} = val(logical(binind(i,:) - '0'));
end

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Numeric Types에 대해 자세히 알아보기

태그

질문:

2015년 1월 26일

편집:

2015년 1월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by