Random Number from a given vector of numbers

1 回表示 (過去 30 日間)
Israa Ahmed
Israa Ahmed 2021 年 8 月 26 日
コメント済み: Israa Ahmed 2021 年 8 月 26 日
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
  1 件のコメント
Israa Ahmed
Israa Ahmed 2021 年 8 月 26 日
Thank you very much, it worked well.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by