"Sam T" <aero.sam.t@gmail.com> wrote in message <i8i83l$mfp$1@fred.mathworks.com>...
> 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 forloop backwards. However, doing this should be faster:
M(r1:r2,:) = [];
Or else you could try this.
M = M([1:r11,r2+1:end],:);
Roger Stafford
