Thread Subject: Removing specific rows from a matrix

Subject: Removing specific rows from a matrix

From: Dominic Pompeo

Date: 21 Jan, 2009 16:59:02

Message: 1 of 2

I have a pretty simple question, but I can't figure out the coding for it.

I have a 12,300 x 12 matrix. I want to code something up that will delete rows that match up based on values in the matrix. I want it to compare the first and second row, based on the values in column one and column two and if they match I want one of the rows deleted. However, I also want it to delete rows that have the sum of columns 3:12 greater than a specified value.

basically...

A =

...
3.4 5.6 10 10 10 10 10 10 10 10 10 10 %row 80
3.4 5.6 10 10 10 10 10 10 10 10 10 10
3.2 5.3 100 100 100 100 100 100 100 100 100 100
...

I want the code to run through each row - see that rows 80 and 81 match based on the first two values and then delete either row 80 or 81 and then see that in row 82 the sum of the last 10 columns is greater than 200 so it will delete that row also. The matching based on the first two columns will always occur consecutively if that helps with the coding. I.E the matches will always be in consecutive rows 85 & 86 or 190 & 191.

I want the final output to just be

A=
...
3.4 5.6 10 10 10 10 10 10 10 10 10 10 %row 80
...

Any help will be greatly appreciated. I know it may not be very clear, if anyone needs a better explanation, post and I will try my best to clear up any confusion.

Subject: Removing specific rows from a matrix

From: Mohammad Monfared

Date: 21 Jan, 2009 17:32:03

Message: 2 of 2

"Dominic Pompeo" <newbiee1987@yahoo.com> wrote in message <gl7k8m$oce$1@fred.mathworks.com>...
> I have a pretty simple question, but I can't figure out the coding for it.
>
> I have a 12,300 x 12 matrix. I want to code something up that will delete rows that match up based on values in the matrix. I want it to compare the first and second row, based on the values in column one and column two and if they match I want one of the rows deleted. However, I also want it to delete rows that have the sum of columns 3:12 greater than a specified value.
>
> basically...
>
> A =
>
> ...
> 3.4 5.6 10 10 10 10 10 10 10 10 10 10 %row 80
> 3.4 5.6 10 10 10 10 10 10 10 10 10 10
> 3.2 5.3 100 100 100 100 100 100 100 100 100 100
> ...
>
> I want the code to run through each row - see that rows 80 and 81 match based on the first two values and then delete either row 80 or 81 and then see that in row 82 the sum of the last 10 columns is greater than 200 so it will delete that row also. The matching based on the first two columns will always occur consecutively if that helps with the coding. I.E the matches will always be in consecutive rows 85 & 86 or 190 & 191.
>
> I want the final output to just be
>
> A=
> ...
> 3.4 5.6 10 10 10 10 10 10 10 10 10 10 %row 80
> ...
>
> Any help will be greatly appreciated. I know it may not be very clear, if anyone needs a better explanation, post and I will try my best to clear up any confusion.

Hi,
I think this would work:

A(diff(A(:,1))==0 & diff(A(:,2))==0,:)=[];
A(sum(A(:,3:12),2)>200,:)=[];

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
matrix manipula... Dominic Pompeo 21 Jan, 2009 12:00:11
delete Dominic Pompeo 21 Jan, 2009 12:00:11
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com