Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

could anyone help me to solve the following issue.

1 vue (au cours des 30 derniers jours)
jaah navi
jaah navi le 13 Mai 2019
Clôturé : MATLAB Answer Bot le 20 Août 2021
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 commentaires
Walter Roberson
Walter Roberson le 13 Mai 2019
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 le 13 Mai 2019
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

Réponses (0)

Cette question est clôturée.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by