How do I sample a random value from a matrix?

3 ビュー (過去 30 日間)
Ethan Correa
Ethan Correa 2018 年 5 月 2 日
コメント済み: Ethan Correa 2018 年 5 月 2 日
Let's say I have a random matrix:
A = rand(10,4)
How can I sample a random value from this matrix (without replacement)? Essentially how can I perform a randsample but for a matrix instead of a vector?

採用された回答

Akira Agata
Akira Agata 2018 年 5 月 2 日
If you want to obtain k samples randomly from A, the following will do that.
ind = randperm(numel(A),k);
output = A(ind);
  1 件のコメント
Ethan Correa
Ethan Correa 2018 年 5 月 2 日
That did the trick, thank you very much!

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

その他の回答 (0 件)

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by