フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

could anyone help me to solve the following issue.

1 回表示 (過去 30 日間)
jaah navi
jaah navi 2019 年 5 月 13 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
code:
A=partitions(4,3)
total_number_of_partitions = length(A)
idx=randperm(total_number_of_partitions,1)
iwant= A(idx)
partdisp(iwant)
The code executes and gives me the result.
when i run the code then command line which gives idx needs to be changed every time.
In my main code i will running the above code more than one time.
while running the code more than one time sometimes idx remains the same.
Actually the idx number needs to be changed everytime when i execute the code.
so i need to have the code in such a way the idx needs to be checked first,if it remains to be the same it should be changed and then displayed and if it is different then it can be displayed.
could anyone please help me on this.
  3 件のコメント
Walter Roberson
Walter Roberson 2019 年 5 月 13 日
Dennis's approach is a good one if you want to use each possible value exactly once.
However, the question in the form written only forbids using the same value as the immmediately after, and does not forbid (for example) the sequence 7, 3, 7, 3, 7, 3, ... since that satisfies that it is changing each time.
Dennis
Dennis 2019 年 5 月 13 日
Good point Walter. Here is an alternative approach:
A=1:5;
idx=randi(size(A,2),1,1000);
idx=idx(find(diff(idx)));
for i=1:numel(idx)
disp(A(idx(i)))
end

回答 (0 件)

この質問は閉じられています。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by