randomly selecting and deleting rows from a matrix
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
James Tursa
2016-11-1
编辑:James Tursa
2016-11-1
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,:) = [];
更多回答(1 个)
Yushuo
2022-7-6
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!