Random Number from a given vector of numbers

조회 수: 9 (최근 30일)
Israa Ahmed
Israa Ahmed 2021년 8월 26일
댓글: Arik Brown 2024년 4월 20일 0:45
Given a vector of certain allowed numbers,
how to generate another vector whose elements randomly take values from that vector of numbers?

채택된 답변

Stephen23
Stephen23 2021년 8월 26일
편집: Stephen23 2021년 8월 26일
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
Israa Ahmed
Israa Ahmed 2021년 8월 26일
Thank you very much, it worked well.
Arik Brown
Arik Brown 2024년 4월 20일 0:45
Thank you.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Random Number Generation에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by