Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: N-dimensional find
Date: Fri, 8 May 2009 12:03:03 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 21
Message-ID: <gu171n$rg$1@fred.mathworks.com>
References: <gnhibi$s1m$1@fred.mathworks.com> <gnhrhd$llc$1@fred.mathworks.com> <gni2rp$3ja$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1241784183 880 172.30.248.38 (8 May 2009 12:03:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 8 May 2009 12:03:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187236
Xref: news.mathworks.com comp.soft-sys.matlab:538477


"Sven" <sven.holcombe@gmail.deleteme.com> wrote in message <gni2rp$3ja$1@fred.mathworks.com>...
> Thanks all,
> 
> The short-term solution I've chosen which has cleaned up my code quite a bit is a combination of suggestions:
> BW = rand(10,20)>.8 % Make the image
> [A, B] = max(BW) % Hijack the max function
> B(BW(B==1)==0) = 0 % Account for all-zero columns
> 
...

If anyone is trying to use this neat trick with *sparse* logical matrices in R2009a, be aware that a MATLAB bug causes a crash: 

http://www.mathworks.com/matlabcentral/newsreader/view_thread/246673

So, if your matrix is sparse and you want your code to be R2009a-compliant, you'll have to do something like:

[A, B] = max(spones(BW)) % converts BW to double to prevent bug

Took me a while to work out what was causing new crashes when moving to R2009a!

AJ