Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Delete some rows where column 1 = certain value

2 vues (au cours des 30 derniers jours)
sm m
sm m le 18 Oct 2016
Clôturé : MATLAB Answer Bot le 20 Août 2021
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?

Réponses (2)

KSSV
KSSV le 18 Oct 2016
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 commentaire
Walter Roberson
Walter Roberson le 18 Oct 2016
You do not need three deletions.
data(ismember(data(:,1), [1, 101, 102]), :) = [];

Andrei Bobrov
Andrei Bobrov le 18 Oct 2016
out = your_data(ismember(your_data(:,1),[67, 22, 32]),:);

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by