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 CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by