Extract numbers from a list
Mostrar comentarios más antiguos
Hi~
There is A=[1:1:37] in matlab, two numbers are randomly drawn from the list A simultaneously, and a total of 74 times are drawn. Requires are as fllows:
1. Each number is drawn 4 times in total.
2. And the same number will not appear twice every time you draw
3. The same number will not be drawn for two consecutive trials.
The final result is expressed as a 74×2 list, each row represents an extraction, the first column indicates the first number drawn, and the second column indicates the second number drawn.
6 comentarios
Stephen23
el 2 de Ag. de 2023
It looks like you will need a WHILE loop, or something similar. What have you tried so far?
Jane
el 2 de Ag. de 2023
Stephen23
el 2 de Ag. de 2023
"I wonder know how to fufill the reqirement 2?"
By specifying "Replace"=false you have already fulfilled requirement 2.
Jane
el 2 de Ag. de 2023
"I misread it just now, it should be requirement three."
You could make a sample, then test if its elements are different compared to the last sample. If the values are duplicated make another sample (e.g. a WHILE loop).
However you should be thinking about requirement 1, because how you approach that will determine the entire structure of your algorithm and code, probably more than requirements 2 and 3.
Jane
el 3 de Ag. de 2023
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!