Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: please help optimize this ('find' is too slow)
Date: Thu, 4 Dec 2008 06:02:03 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 14
Message-ID: <gh7ror$eno$1@fred.mathworks.com>
References: <gh46f4$pg2$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1228370523 15096 172.30.248.37 (4 Dec 2008 06:02:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 4 Dec 2008 06:02:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:504886


"Jayveer " <jveer@jveer.com> wrote in message <gh46f4$pg2$1@fred.mathworks.com>...
> can anyone please help me speed this up?the line with find is way too slow!
> ........

  First of all, unless your cubic cell faces are each aligned with the three coordinate axes, your code does not appear to make much sense, so I assume that they are so aligned.  If so, you should be dealing with six quantities per cell, not the 3 times 8 for NCx, NCy, and NCz.  These should be for each cell, the lower and upper x-limits, the lower and upper y-limits, and the lower and upper z-limits, of that cell.

  Next, you should select one of the coordinates, say the x-axis, to be involved in a sort operation involving not only the x-values of P(1,:) but also the lower and upper x-limits for each of the cells.  If Lx and Ux are respective row vectors of these limits, you could do a sort on [Lx,Ux,P(1,:)], and this need be done only once.  After the sort is finished it is relatively easy to then extract the corresponding 'nx' for each cell with much less expenditure of execution time than doing a 'find' operation each time, making use of both the sorted list and the accompanying index vector of the sort command.

  After that, the number of points that need to be searched for each cell should be greatly reduced and you can proceed as you have already done in your code with finding ny and then nz.

  I realize the above "relatively easy" part leaves a lot of the work to you but I am hoping you will be able to carry it out on your own.  If it gives you too much trouble, give a cry of distress and perhaps more help can be forthcoming.

Roger Stafford