Thread Subject: Removing specific rows from a matrix

Subject: Removing specific rows from a matrix

From: Jacob

Date: 16 Nov, 2009 10:51:02

Message: 1 of 4

Heya,

Need some help with a problem here...

I have a m*6 matrix as input in a script I'm making. This matrix gets split up into two sub matrices: 'from' and 'to', each m*3 matrices.

Then I have an nchoosek(1:m,3) = indices. In my current example m = 5.

so 'indices' is a 3*10 matrix.

In a loop I now need to remove rows from the 'from' matrix. These rows are in 'indices'.

So first I need to remove the rows indicated by the first line in 'indices', which will be rows 1, 2 and 3. And the second time around I need to remove rows 1, 2 and 4 and so on.


so 'indices', tells me what rows to remove from the 'from' matrix. How do I go about doing that?

I tried A = from(indices == [])
That returned A = []

Best regards,
Jacob Collstrup

Subject: Removing specific rows from a matrix

From: Husam Aldahiyat

Date: 16 Nov, 2009 11:14:02

Message: 2 of 4

"Jacob " <jacob@collstrup.dk> wrote in message <hdraql$cns$1@fred.mathworks.com>...
> Heya,
>
> Need some help with a problem here...
>
> I have a m*6 matrix as input in a script I'm making. This matrix gets split up into two sub matrices: 'from' and 'to', each m*3 matrices.
>
> Then I have an nchoosek(1:m,3) = indices. In my current example m = 5.
>
> so 'indices' is a 3*10 matrix.
>
> In a loop I now need to remove rows from the 'from' matrix. These rows are in 'indices'.
>
> So first I need to remove the rows indicated by the first line in 'indices', which will be rows 1, 2 and 3. And the second time around I need to remove rows 1, 2 and 4 and so on.
>
>
> so 'indices', tells me what rows to remove from the 'from' matrix. How do I go about doing that?
>
> I tried A = from(indices == [])
> That returned A = []
>
> Best regards,
> Jacob Collstrup

Try this?

for k = 1:size(indices,1) % in your example 3

temp = from;
temp(indices(k,:),:) = [];
A = temp;

end

Subject: Removing specific rows from a matrix

From: Jacob

Date: 16 Nov, 2009 11:34:03

Message: 3 of 4

> Try this?
>
> for k = 1:size(indices,1) % in your example 3
>
> temp = from;
> temp(indices(k,:),:) = [];
> A = temp;
>
> end

That doesn't seem to work. I get this error:

??? Index of element to remove exceeds matrix dimensions.

Error in ==> RANSAC_trans_test at 130
    temp(indices(i,:),:) = [];
 

I think I know whats wrong, but not how to correct it.

I don't think I explained myself correctly in the first post. The indices matrix is 10*3
My loop runs from 1 to size(indices,1). The rows of the 'indices' matrix contains the row-numbers that are to be removed from the 'from' matrix.

The first row in 'indices' is [1 2 3], meaning that the rows 1, 2 and 3 needs to be removed from the 'from' matrix in the first iteration.

In the next iteration I need to remove rows 1, 2, 4 from the original 'from' matrix (5*3).

Does that make sense?

Best regards,
Jacob

Subject: Removing specific rows from a matrix

From: Jacob

Date: 16 Nov, 2009 11:50:03

Message: 4 of 4

"Jacob " <jacob@collstrup.dk> wrote in message <hdrdbb$5qg$1@fred.mathworks.com>...
> > Try this?
> >
> > for k = 1:size(indices,1) % in your example 3
> >
> > temp = from;
> > temp(indices(k,:),:) = [];
> > A = temp;
> >
> > end

Wait, it does work. I just screwed up with the variable names. That bit of code works like a charm!!

Thanks for the help!

Best regards

Jacob

Tags for this Thread

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.

rssFeed for this Thread

Contact us at files@mathworks.com