problem with using randsample
Afficher commentaires plus anciens
Hi, I have a set that its members change in a loop and I want to select just one member of it randomly and evaluate the result. the written code is as below:
CandidateNode = randsample(UnvisitedNode,1);
it works good but sometimes its result is not acceptable. for example when UnvisitedNode=[3] running this code have different result. sometimes CandidateNode=[1], sometimes CandidateNode=[2] and sometimes CandidateNode=[3] how could I fix it? tanx in advanced
2 commentaires
KALYAN ACHARJYA
le 7 Nov 2018
Sorry, the question is not understood. Kindly clarify?
mehdi J
le 7 Nov 2018
Réponse acceptée
Plus de réponses (1)
Aaron Schnydrig
le 6 Oct 2020
0 votes
The question is quite old, but for the ones finding it over Google (like I did):
The simplest answer would be the following:
CandidateNode = randsample(repmat(UnvisitedNode, 2, 1),1)
The repmat() function uses every value of your vector twice. Therefore, it will not change the probability of a certain element. However, it will make sure that your vector always has more than one element and is therefore used as a population.
Catégories
En savoir plus sur Triangular Distribution dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!