randomly select elements of an array
Mostrar comentarios más antiguos
Hi How i can select randomly elements from a matrix o array
I have the matrix and i want to select "x" numbers of elements
thanks
Respuesta aceptada
Más respuestas (2)
Prasobhkumar P. P.
el 28 de Jul. de 2020
Editada: Walter Roberson
el 3 de Sept. de 2021
histHandle= histfit(data,nBins,'normal');
[Val Ind] = max(histHandle(2).YData); %histHandle(2) corresponds to the curve fitted
M = histo18(2).XData(Ind);
Adam Wyatt
el 3 de Sept. de 2021
Editada: Adam Wyatt
el 3 de Sept. de 2021
Use "randsample"
For array:
Arry = [1 4 5 7 8 9];
Smpl = randsample(Arry, 3)
For strings:
Arry = ["Yellow" "Green" "Blue" "Orange" "Black" "Grey" "Red" "Brown" "Purple" "White"];
Smpl = randsample(Arry, 2)
How do you want to sample the matrix? If its any element, just convert to array (e.g. Mat(:)). Otherwise you have to apply the function to each row/column separately.
3 comentarios
Walter Roberson
el 3 de Sept. de 2021
Note: randsample() is from the Statistics and Machine Learning Toolbox
Piyush Kant
el 7 de Feb. de 2022
Is there any method/parameter with which we can reproduce same random series so that the different algorithms can be evaluated? I know that way it wont be a random series anymore still the psudorandomness can be helpful for multiple runs.
Steven Lord
el 7 de Feb. de 2022
Some older functions that use random numbers internally (like eigs, which generates a starting point at random if one is not given to it) have the ability to specify inputs that avoid the randomness (in the case of eigs by specifying v0 in the options structure or specifying the StartVector name-value pair argument.)
Categorías
Más información sobre Random Number Generation 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!