Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: how to insert/delete rows in a matrix without copy the rest of matrix
Date: Wed, 25 Jul 2007 16:20:01 +0000 (UTC)
Organization: No matter
Lines: 45
Message-ID: <f87t7h$mje$1@fred.mathworks.com>
References: <f87kg3$9ri$1@fred.mathworks.com> <f87ooi$rma$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-00-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1185380401 23150 172.30.248.35 (25 Jul 2007 16:20:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 25 Jul 2007 16:20:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 859211
Xref: news.mathworks.com comp.soft-sys.matlab:421021



Thank you, but this is not a "true" solution.  The codes are just for illustration of the problem.  What if you want to delete/add the 99th row?  

The problem lies Matlab copying whole matrix while actually only a very small portion of the matrix being modified.
I guess to really solve this problem we have to find a data-structure that allows a matrix to span multiple memory segments and are somehow linked together by indexing pointers. 

"Daphne W" <daphnew_too_nospam@yahoo.com> wrote in message <f87ooi$rma$1@fred.mathworks.com>...
> 
> The speed of the calculation partially depends on the system you're workin on. 
> On my laptop got 
> Elapsed time is 0.415618 seconds.
> Elapsed time is 0.415288 seconds.
> For your code.
> 
> Trying to do this faster, I simply redefined the a matrix without the first column as you have: 
> 
> a=rand(5000);
> tic; a=a(:,2:end); toc
> Elapsed time is 0.250436 seconds.
> Not great, but a bit better. 
> 
> Daphne
> 
> 
> 
> "Chenyang " <john.doe.nospam@mathworks.com> wrote in 
> message <f87kg3$9ri$1@fred.mathworks.com>...
> > Matlab is very slow add/delete a row in a matrix.
> > It always trying to copy the whole matrix
> > e.g., 
> > 
> > a = rand(5000);
> > tic
> > a(:,1) = [];
> > toc
> > tic
> > a = [a(:,1),a];
> > toc
> > Elapsed time is 0.447241 seconds.
> > Elapsed time is 0.556416 seconds.
> > 
> > I need to insert/delete a row into a large matrix.
> > How to make it fast?
> > 
>