フィルターのクリア

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
  1 件のコメント
주몽 고
주몽 고 2020 年 11 月 2 日

サインインしてコメントする。

採用された回答

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 Center および File ExchangeSimulink についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by