How to select particular rows of a matrix?
Show older comments
I have a matrix (say 100 x 33). I need to select particular rows of the matrix wherein the row numbers are given by a random function.
Answers (2)
Guillaume
on 28 Jan 2016
m = reshape(1:100*33, 33, 100)'; %demo matrix
rowindices = randperm(size(m, 1), 5); %demo data, choose 5 rows at random
mrows = m(rowindices, :)
Star Strider
on 28 Jan 2016
This works:
M = randi(99, 100, 33); % Create Matrix
Rows = randi(size(M,1), 10, 1); % Randomly Choose 10 Rows
Out = M(Rows,:);
3 Comments
Pavithra Balakrishnan
on 28 Jan 2016
Star Strider
on 28 Jan 2016
My pleasure!
If my Answer solved your problem, please Accept it.
Guillaume
on 28 Jan 2016
I would use randperm instead of randi so that you are guaranteed to select different rows
Categories
Find more on Matrix Indexing 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!