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: NNTP Server
Lines: 22
Message-ID: <lfba03$49a$>
References: <lfat6s$te$>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
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: 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