From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: optimum way of deleting specified number of rows from matrix
Date: Wed, 6 Oct 2010 17:53:20 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 28
Message-ID: <i8id2g$loi$>
References: <i8i83l$mfp$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1286387600 22290 (6 Oct 2010 17:53:20 GMT)
NNTP-Posting-Date: Wed, 6 Oct 2010 17:53:20 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: comp.soft-sys.matlab:676317

"Sam T" <> wrote in message <i8i83l$mfp$>...
> Hi,
> I have a matrix (lets say 10k x 10k) and I want to delete all rows starting from 'r1' and ending at 'r2'. What do you think is the best way to carry out this operation. 
> At this moment I use the "for" loop as follows, and I am sure that there exist better and more optimum ways of doing it. I realize that there are other threads in Matlab central which correspond to similar issue, but I was not able to get much out of them for this specific problem where I am deleting rows from r1 to r2. 
> My current approach:
> for j= r2 :-1: r1
> matrix(j,:)=[];
> end
> I run into this problem quite often, and the computing time becomes a serious issue when the difference b/w r1 and r2 i.e. (r2 - r1) is large, along with large matrices. I am looking for a better approach to solve this. 
> I will appreciate if other folks of this community can let me know their thoughts on this.
> Thanks so much. 
- - - - - - - -
  You are right to run your for-loop backwards.  However, doing this should be faster:

 M(r1:r2,:) = [];

Or else you could try this.

 M = M([1:r1-1,r2+1:end],:);

Roger Stafford