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

Subject: Deleting rows

From: Derrick

Date: 25 Dec, 2012 03:35:09

Message: 1 of 4

Hello,
I am new to MATLAB and any help, even links, would be appreciated. I have a data set in which I would like to delete 8 rows every 128 points. How would I go about doing this? My data set is 8192X32.
Thanks
Derrick

Subject: Deleting rows

From: Roger Stafford

Date: 25 Dec, 2012 04:21:07

Message: 2 of 4

"Derrick " <kaseman.7@gmail.com> wrote in message <kbb6td$q1p$1@newscl01ah.mathworks.com>...
> Hello,
> I am new to MATLAB and any help, even links, would be appreciated. I have a data set in which I would like to delete 8 rows every 128 points. How would I go about doing this? My data set is 8192X32.
> Thanks
> Derrick
- - - - - - - - - -
  I assume you mean you want to delete 8 consecutive rows every 128 rows starting with the first 8 rows.

 A = rand(8192,32);
 A(bsxfun(@plus,(1:8).',0:128:8064),:) = [];

Roger Stafford

Subject: Deleting rows

From: Nasser M. Abbasi

Date: 25 Dec, 2012 04:55:46

Message: 3 of 4

On 12/24/2012 9:35 PM, Derrick wrote:
> Hello,
> I am new to MATLAB and any help, even links, would be appreciated. I have a data set
> in which I would like to delete 8 rows every 128 points. How would I go about doing this?
>My data set is 8192X32.
> Thanks
> Derrick
>

another way. To illustrate first on simple vector A=1:16,
and say you want to delete first 2 rows each segment of length 4.

--------------------------
n = 2 %number of rows to delete
A = 1:16;
idx1 = 4:4:16;
idx2 = idx1-(n-1);
A(cell2mat(arrayfun(@(i) idx2(i):idx1(i),1:length(idx1),'UniformOutput',false)))=[]
----------------------

A =
      1 2 5 6 9 10 13 14

To delete 3 rows each 4 segments, replace n by 3 above:

A =
      1 5 9 13

Lets test it on a matrix, 16 rows, 2 columns. again, remove
first 2 rows each 4 segments

-------------------------------------
n = 2;
A = [(1:16)' repmat(99,[16,1])]
idx1 = 4:4:N;
idx2 = idx1-(n-1);
A(cell2mat(arrayfun(@(i) idx2(i):idx1(i),1:length(idx1),'UniformOutput',false)),:)=[]
-------------------------------------------

A =
      1 99
      2 99
      5 99
      6 99
      9 99
     10 99
     13 99
     14 99

ok, now use it on your data

-----------------------
n = 8; %rows to delete
A = rand(8192,32);
idx1 = 128:128:8192;
idx2 = idx1-(n-1);
A(cell2mat(arrayfun(@(i) idx2(i):idx1(i),1:length(idx1),'UniformOutput',false)),:)=[]
----------------------------------

--Nasser

Subject: Deleting rows

From: Derrick

Date: 25 Dec, 2012 19:35:07

Message: 4 of 4

Thank you it worked great!

Tags for this Thread

No tags are associated with 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