How to randomly select entire row from matrix?

2 views (last 30 days)
Liza
Liza on 29 Nov 2013
Commented: Image Analyst on 29 Nov 2013
Hello! I have a matrix of size 198220*15, which contains year and physical characteristics of this year. And I need to randomly select a 100 rows from it, but it should be entire row selected randomly, so that the year and it's characteristics didn't mess up during this process.
I tried:
k = randperm(size(kx3,1));
mnew = kx3(k(1:100),:);
but it just selects independantly from each column, so characteristics of year 2003 go to year 2011, etc.
Thank you in advence!

Answers (1)

Wayne King
Wayne King on 29 Nov 2013
A = randn(198220,15);
idx = sort(randperm(size(A,1),100));
B = A(idx,:);

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!