フィルターのクリア

How to create a vector of randomly selected elements from a matrix?

1 回表示 (過去 30 日間)
virkuz000
virkuz000 2018 年 2 月 21 日
コメント済み: virkuz000 2018 年 2 月 21 日
I am trying to create a one dimensional vector of size n from randomly selected elements of a matrix. I am not trying to select a random row or a random column from the matrix. I am just trying to create a vector from random matrix elements and have the size of my vector determined. For example:
A = [1 2 3 4 5; 6 7 8 9 10; 11 12 13 14 15];
And I'm looking for something like the following if I wanted a vector of size 6:
B = [15 2 13 8 1 10]
I tried using "datasample" but that just created another 2D matrix instead of a one dimensional vector. Any ideas?
Thanks for the help!

採用された回答

Birdman
Birdman 2018 年 2 月 21 日
B=randsample(A(:),6)

その他の回答 (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