How to shuffle numbers for each iteration?
Show older comments
I am having 'n' randomnly generated positive decimal number. With this input I have performed some set of mathematical calculations. Now i need to repeat the mathematical calculations with changed order of decimal number and this has to be followed for each iteration until a certain condition is met.
Example:
A= 5, 2, 4, 3, 7, 1, 6
Expected output: Shuffle decimal number for each iteration. [only positive number is required]
7 Comments
Jiri Hajek
on 12 Jan 2023
Hi, your question is not very clear. Do you need to permute digits in a number?
Dyuman Joshi
on 12 Jan 2023
Do you need the numbers 1 to 7 in a (different) random order for each iteration?
ASHA PON
on 12 Jan 2023
Try randperm -
Or if you want all permutations in once, and then loop through them, check out perms()
n=7;
iter=10;
for idx=1:iter
randperm(n)
end
ASHA PON
on 12 Jan 2023
ASHA PON
on 19 Jan 2023
Dyuman Joshi
on 19 Jan 2023
Can you show your code? Without the code, it is difficult to tell where the problem is.
Answers (1)
Tobias
on 12 Jan 2023
It seems you try to do something like a minmum search. Probably, you can solve the origin problem in a more target oriented way.
For your question to shuffle a vector you could do something like this:
Expect having a vector with several digits. In this example 1 to 7:
vector = 1:7;
For example, you could shuffle it like this:
vector = vector(randperm(length(vector)));
Categories
Find more on Multirate Signal Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!