필터 지우기
필터 지우기

Find all subset index of an array whose sums equal or nearest to a given target

조회 수: 1 (최근 30일)
  • target = 700
  • array = [200 250 340 100 500 360]
  댓글 수: 3
Stalin Samuel
Stalin Samuel 2015년 9월 26일
yes sir.but i need the elements without Repetition
Walter Roberson
Walter Roberson 2015년 9월 26일
So 200,200,200,100 would be accepted as long as no other permutation of those values was emitted?

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

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2015년 9월 26일
a = dec2bin((0:bin2dec(sprintf('%d',ones(1,numel(array)))))')-'0';
k = bsxfun(@times,a,array);
d = abs(sum(k,2) - 700);
out = k(d == min(d),:);

카테고리

Help CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by