From: "Jveer " <>
Newsgroups: comp.soft-sys.matlab
Subject: Re: please help optimize this ('find' is too slow)
Date: Sat, 6 Dec 2008 21:36:03 +0000 (UTC)
Organization: University of Manchester
Lines: 34
Message-ID: <gher83$sfd$>
References: <gh46f4$pg2$> <gh7ror$eno$> <gh7vs8$fgq$> <gh9faq$fb4$> <gh9qmi$l5c$> <gh9ske$6he$> <gha1vj$850$> <ghefbe$ell$>
Reply-To: "Jveer " <>
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: 1228599363 29165 (6 Dec 2008 21:36:03 GMT)
NNTP-Posting-Date: Sat, 6 Dec 2008 21:36:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1206797
Xref: comp.soft-sys.matlab:505397

hello Roger, thank you for the quick replies

i've tried your latest recommendations before. I'm afraid they either dont work or dont provide any speed improvements at all

1. the && doesnt work with vectors. it gives the following error msg: "??? Operands to the || and && operators must be convertible to logical scalar values."

2. as for keeping the min,max outside the loop, i did the following:
Uy=max(NCy,[],2)';Ly=min(NCy,[],2)';Uz=max(NCz,[],2)';Lz=min(NCz,[],2)'; (outside loop)
and then changed the inside loop statements to these:
however no incr in speed. the main drawback from this method is that i'll have FOUR additional very long variables coz the column length of P is typically more than 350k
for any decent simulation. therefore from a memory optimization perspective it is not desirable.

3. the ~isempty test hardly takes any time. also in MOST CASES they are empty. this test is kinda my workout not being able to use short-circuit  &&. 

removing the ~isempty tests dont increase speed. i understand your point that matlab understands how to deal with nx=[]. i included out of a 'paranoia' that matlab will run unnecessary of the inside brackets before realising that nx=[]; nx(P(2,nx)>=min(NCy(c,:))&P(2,nx)<max(NCy(c,:)));

correction from my last post the function PinC runs the same amount of the time steps, not 600k- more like 200-800 typically.

i was wondering if there any chance of using a similar method to the one u came up with to replace the 'find' function. i was well impressed by that and i still dont fully understand it.

the 2 time consuming lines in my current function are:

they both sort of do what that find function did except they use logicals. referring to an older version in the first post, i broke down that long logical so that the above two lines operate on subsets instead of the whole range of terms(typically 350k for every row)

any other recommendations you may have are most welcome.

"Roger Stafford" <> wrote in message <ghefbe$ell$>...
> "Jayveer " <> wrote in message <gha1vj$850$>...
>   I notice a couple of other aspects of your code that you could change to possibly improve its timing efficiency, Jayveer.