randomly selecting and deleting rows from a matrix
5 views (last 30 days)
Show older comments
b = X; %X is a 600 by 40 matrix
xnew = b(randperm(427),:);
i want to determine the 173 rows in b that were not selected i could also delete the selected 427 rows from b to obtain the remaining unselected rows can anyone help me do this?
your help is much appreciated
0 Comments
Accepted Answer
James Tursa
on 1 Nov 2016
Edited: James Tursa
on 1 Nov 2016
Your code is likely not doing what you think it is doing. The randperm(427) call gives you a permutation of the numbers 1,2,...,427. So ALL of the rows from 1-427 are selected and the rows not selected are always 428-600. From your description, it sounds like what you really wanted was to randomly select 427 out of 600. I.e., is this what you really want?
k = randperm(600,427); % <-- 427 random integers from the set 1-600 (no replacement)
xnew = b(k,:); % <-- select the random rows
m = ~ismember(1:600,k); % <-- get logical indexes of other rows
xother = b(m,:); % <-- the other rows
Another way to get the other rows per your suggestion:
xother = b;
xother(k,:) = [];
More Answers (1)
Yushuo
on 6 Jul 2022
I just used if the code line number divide by 2 reminder is 0 then delete it
A=[0.5666 0.3169 ; 0.5181 0.3317 ; 0.6645 0.0650 ; 0.0188 0.5120 ; 0.8007 0.4257 ];
disp (A);
for oooo=1:size(A,1)
if rem(oooo , 2)==0
A(oooo,:)=[];
end
end
disp (A);
0 Comments
See Also
Categories
Find more on Logical 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!