Use cvpartition to generate a set of random 3 numbers 100 or 1000 times
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hello Everyone
I need to generate random sets of data (three numbers) selected for numbers between 1 and 30. So I used
c = cvpartition(30,'KFold',3)
So, the result is always
TrainSize: 21 20 21
TestSize: 10 11 10
However, I need to repeat this 100 or 1000 times and get different TrainSize numbers each time.
Does anyone know how to:
- Prevent Matlab from giving the same numbers each time?
- Allow cvpartition to give me 100 or 1000 TrainSize numbers at the same time, instead of calling the function 100 or 1000 times?
Thank you.
Best,
0 Commenti
Risposte (1)
the cyclist
il 17 Mar 2023
Modificato: the cyclist
il 17 Mar 2023
I don't think cvpartition does what you intend, and I am quite sure that you don't understand its output. Rather than explain cvpartition, here is my guess about what you intend, and an easier way to get it.
You want to choose 3 random numbers from the set 1:30, right? And you want to do this 100 times (or 1000, or whatever), right?
The method depends on whether you want to allow repeated values within each set of 3.
If repeated values are allowed, then
NG = 30;
NT = 7; % I'm using 7 instead of 100, so we can see all the results
N = 3;
x = randi(NG,NT,N) % Generate 7 sets of 3 values, REPEATS ALLOWED
If repeated values are NOT allowed, then
x = zeros(NT,N);
for ni = 1:NT
x(ni,:) = randperm(NG,N);
end
x
I couldn't remember or easily find a way to do the 2nd method without a loop, but it might exist.
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!