# choose some random number from the given number matlab

3 visualizzazioni (ultimi 30 giorni)
Matlab111 il 28 Lug 2014
Modificato: Patrik Ek il 28 Lug 2014
a=[0.1,0.1,0.1,0.2,0.3];
from this i want to choose some random number
Note: answer may be like "a=0.1,0.2"
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Patrik Ek il 28 Lug 2014
Modificato: Patrik Ek il 28 Lug 2014
Ok, I assume that the example "a=[1 1 2 4 5 1 1 1]; than the answer should be b= 1 3 1" had a typo and that you want to randomly select a number of samples from a vector a. This is how I normally do it.
a=[0.1,0.1,0.1,0.2,0.3];
nSamples = 3;
tmp = rand(size(a));
[~,idx] = sort(tmp);
idx = idx(1:nSamples);
b = a(idx);
clear tmp;
This creates a vector of randomly generated numbers, from an uniform distribution and when sorted, the random numbers will be linearly increasing and the original indices will be uniformly distributed.
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Matlab111 il 28 Lug 2014
wow nice thank you

Accedi per commentare.

### Categorie

Scopri di più su Uniform Distribution (Continuous) in Help Center e File Exchange

### Tag

Non è stata ancora inserito alcun tag.

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by