How can I extract random data from a matrix?

2 ビュー (過去 30 日間)
Gerardo
Gerardo 2012 年 9 月 14 日
Hi everyone.
I have a M rows by N columns matrix and I need to extract X random samples of it of the same size. I suposse is a simple task but I'm new at Matlab.
Thanks a lot.

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 9 月 14 日
編集済み: Azzi Abdelmalek 2012 年 9 月 14 日
A=rand(10,5) %your matrix aray
B=A(:)
X=20; %number of random sample
[v,idx]=sort(rand(1,numel(A)));
Samples=B(idx(1:X))
  2 件のコメント
Gerardo
Gerardo 2012 年 9 月 16 日
Thanks for your help Azzi, it works great.
Azzi Abdelmalek
Azzi Abdelmalek 2012 年 9 月 16 日
using Sean Wolski suggestion (randperm)
A=rand(10,5) %your matrix aray
Samples=A(randperm(numel(A),20))

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

その他の回答 (1 件)

Sean de Wolski
Sean de Wolski 2012 年 9 月 14 日

カテゴリ

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