필터 지우기
필터 지우기

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