필터 지우기
필터 지우기

subset algorithm! How to follow?

조회 수: 1 (최근 30일)
주몽 고
주몽 고 2020년 11월 2일
편집: Rishik Ramena 2020년 11월 5일
% code
n = input('n:') % n=[1,2,3,4,5,6]
j = input('j:') % j=3
subset = [1:j] %subset = [1,2,3]
h = j+1. %h=4
found = [false*j]
while h>1 and found == false;
h = h-1. %h=3
if subset(h)<n+h-j
found(h) = true
end;
end;
if found(h) == false;
subset;
end;
else
subset(h) = subset(h) + 1
for k = h+1:j %k = [5:3]??
subset(k) = subset(k-1) + 1
subset
end;
end;
I coded with MATLAB. However,there are areas that do not work well. How do I follow this algorithm? please

채택된 답변

Rishik Ramena
Rishik Ramena 2020년 11월 5일
편집: Rishik Ramena 2020년 11월 5일
A few points to note regarding the implementation of the algorithm:
  • step 12 could be implemented by using a while loop.
  • And the algorithm does not specify that FOUND needs to be an array.
  • Also do note the termination of the algorithm at step 7.
n = input('n:'); % n=4
j = input('j:'); % j=2
subset = 1:j % subset = [1,2]
while(true) %% step 3
h = j+1; % h=3
found = false;
while (h>1) && (found == false)
h = h-1; %h=2
if subset(h)<(n+h-j)
found = true;
end
end
if found == false
return % exit (step 7)
else
subset(h) = subset(h) + 1;
for k = h+1:j % (step 9)
subset(k) = subset(k-1) + 1;
end
subset(1:j) % step 11
end % goto step 3
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by