Random Number from a given vector of numbers

9 Ansichten (letzte 30 Tage)
Israa Ahmed
Israa Ahmed am 26 Aug. 2021
Kommentiert: Arik Brown am 20 Apr. 2024 um 0:45
Given a vector of certain allowed numbers,
how to generate another vector whose elements randomly take values from that vector of numbers?

Akzeptierte Antwort

Stephen23
Stephen23 am 26 Aug. 2021
Bearbeitet: Stephen23 am 26 Aug. 2021
V = [-1,23,99,111,1024];
N = 3;
A = V(randi(numel(V),1,N)) % with repetition
A = 1×3
111 111 1024
B = V(randperm(numel(V),N)) % no repetition
B = 1×3
1024 111 23
  2 Kommentare
Israa Ahmed
Israa Ahmed am 26 Aug. 2021
Thank you very much, it worked well.
Arik Brown
Arik Brown am 20 Apr. 2024 um 0:45
Thank you.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Random Number Generation finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by