How can I extract random data from a matrix?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
0 comentarios
Respuesta aceptada
Azzi Abdelmalek
el 14 de Sept. de 2012
Editada: Azzi Abdelmalek
el 14 de Sept. de 2012
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 comentarios
Azzi Abdelmalek
el 16 de Sept. de 2012
using Sean Wolski suggestion (randperm)
A=rand(10,5) %your matrix aray
Samples=A(randperm(numel(A),20))
Más respuestas (1)
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!