Path: news.mathworks.com!newsfeed-00.mathworks.com!news.kjsl.com!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!rt.uk.eu.org!aioe.org!.POSTED!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: fast way to get second output of min
Date: Thu, 06 Mar 2014 20:12:43 -0600
Organization: Aioe.org NNTP Server
Lines: 22
Message-ID: <lfba03$49a$1@speranza.aioe.org>
References: <lfat6s$te$1@newscl01ah.mathworks.com>
NNTP-Posting-Host: btGmldVELOIjATn89YpiGw.user.speranza.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Complaints-To: abuse@aioe.org
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:12.0) Gecko/20120428 Thunderbird/12.0.1
X-Notice: Filtered by postfilter v. 0.8.2
Xref: news.mathworks.com comp.soft-sys.matlab:810402

On 3/6/2014 4:35 PM, Christian wrote:
> Hi all,
>
> I'm looking for a faster way for the following code:
>
> for k1=1:K1
>   for k21=1:K2
>     for k22=1:K2
>       [~, xind(k1,k21,k22)] ...

1) Have you preallocated xind?

2) Reverse the order of the loops and traverse in column-major order. 
Your loop order could be causing cache misses continually depending on 
size of the array.  This could be a reason the mex didn't help any 
significant amount.

I don't see anything to be done just because you're only looking at the 
location.

--