Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How do I conditionally delete rows?

Subject: How do I conditionally delete rows?

From: Jens

Date: 26 Aug, 2009 06:17:18

Message: 1 of 2

Sorry for posting this here probably too trivial for you.... but it drives me nuts

I want to delete rows in a matrix based on the values in a separate vector. So the values in the vector correspond to the row numbers I want to delete. What would be the fastest way to do this?

Thanks

Jens

Subject: How do I conditionally delete rows?

From: Perttu Ranta-aho

Date: 26 Aug, 2009 06:31:04

Message: 2 of 2

"Jens " <jokroemer@googlemail.com> wrote in message <h72k1e$1ta$1@fred.mathworks.com>...
> Sorry for posting this here probably too trivial for you.... but it drives me nuts
>
> I want to delete rows in a matrix based on the values in a separate vector. So the values in the vector correspond to the row numbers I want to delete. What would be the fastest way to do this?
>

One of the ways, may not be the fastest if A is big:

A=reshape(1:20,10,2);
b=1:2:10;
A(b,:) = []
%{
A =

     2 12
     4 14
     6 16
     8 18
    10 20
%}

_perttu

Tags for this Thread

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.

Contact us