Info
此问题已关闭。 请重新打开它进行编辑或回答。
Delete some rows where column 1 = certain value
8 次查看(过去 30 天)
显示 更早的评论
How can I delete only the rows where the column1 value = 1 or 101 or 102
My matrix is 10000 *137. i WANT TO DELETE ALL THE ROWS WHERE MY COLUMN 1 ENTRY IS EITHER OF THESE VALUES. Unique values in my column1 are 1, 101, 102, 105, 34,45,67,22,32
The other option I have is : I want to retain only those rows where my columns are 67, 22, 32 Are there specific commands tht I can use for these two situations?
0 个评论
回答(2 个)
KSSV
2016-10-18
data = rand(100,2) ; % random data
% add 1,101,102 randomly
data(randsample(1:100,10),1) = 1 ;
data(randsample(1:100,7),1) = 101 ;
data(randsample(1:100,15),1) = 102 ;
%%remove rows with 1 , 101 and 102
data(data(:,1)==1,:) = [] ;
data(data(:,1)==101,:) = [] ;
data(data(:,1)==102,:) = [] ;
1 个评论
Walter Roberson
2016-10-18
You do not need three deletions.
data(ismember(data(:,1), [1, 101, 102]), :) = [];
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!