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:
Deleting rows from column

Subject: Deleting rows from column

From: Sven Schoeberichts

Date: 22 Oct, 2010 20:09:03

Message: 1 of 4

Hey all,

I have a single column of data. Data length is n*19, as it is generated by a 19 sample cycle.

From every cycle I need to have the 2nd value deleted, so for example, I have a column like this:
1
2
3
4
5
6
...
...
190
which is 10 cycles of 19 samples each.

I need to have number 2 deleted, number 21, number 40, etc...

I tried to set up a loop, deleting every 19th row, starting from the 2nd.
The problem I encounter is that as soon as one row gets deleted, the index changes (so after deleting number 2, number 3 becomes number 2, which next causes number 20, instead of 21, to be deleted).

There must be a simple way to deal with this problem, can anyone help?

Thanks in advance,

Cheers!

Sven

Subject: Deleting rows from column

From: Sean

Date: 22 Oct, 2010 20:21:03

Message: 2 of 4

"Sven Schoeberichts" <sven@wires.nl> wrote in message <i9sr0v$ntc$1@fred.mathworks.com>...
> Hey all,
>
> I have a single column of data. Data length is n*19, as it is generated by a 19 sample cycle.
>
> From every cycle I need to have the 2nd value deleted, so for example, I have a column like this:
> 1
> 2
> 3
> 4
> 5
> 6
> ...
> ...
> 190
> which is 10 cycles of 19 samples each.
>
> I need to have number 2 deleted, number 21, number 40, etc...
>
> I tried to set up a loop, deleting every 19th row, starting from the 2nd.
> The problem I encounter is that as soon as one row gets deleted, the index changes (so after deleting number 2, number 3 becomes number 2, which next causes number 20, instead of 21, to be deleted).
>
> There must be a simple way to deal with this problem, can anyone help?

Well to counteract the indexing problem you're seeing, couldn't you just run it backward ;)

Anyway the better and easier way to do it is:
X(2:19:end) = [];

Subject: Deleting rows from column

From: Matt J

Date: 22 Oct, 2010 20:26:03

Message: 3 of 4

Data(2:19:end)=[];

Subject: Deleting rows from column

From: Sven Schoeberichts

Date: 22 Oct, 2010 20:49:03

Message: 4 of 4

"Matt J " <mattjacREMOVE@THISieee.spam> wrote in message <i9ss0r$srq$1@fred.mathworks.com>...
> Data(2:19:end)=[];

So this will delete the rows all at once, instead of going through a loop... I feel so stupid now :(

Thanks a lot for both your replies!

Gr. Sven

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