Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!d9g2000prh.googlegroups.com!not-for-mail
From: Nathan <ngreco32@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Simple matrix manipulation question
Date: Thu, 16 Jul 2009 14:31:03 -0700 (PDT)
Organization: http://groups.google.com
Lines: 44
Message-ID: <f2dc42d8-7653-4452-bd45-c1688a66044a@d9g2000prh.googlegroups.com>
References: <h3lt89$b6e$1@fred.mathworks.com> <h3o275$2h9$1@fred.mathworks.com> 
	<h3o2o3$7g4$1@fred.mathworks.com> <h3o46t$f27$1@fred.mathworks.com> 
	<h3o54v$hc9$1@fred.mathworks.com>
NNTP-Posting-Host: 198.206.219.33
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1247779863 27117 127.0.0.1 (16 Jul 2009 21:31:03 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Thu, 16 Jul 2009 21:31:03 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: d9g2000prh.googlegroups.com; posting-host=198.206.219.33; 
	posting-account=_KeVcAoAAAB7j3xn35ujaQ0BoQhuzwJP
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1) 
	Gecko/20090624 Firefox/3.5,gzip(gfe),gzip(gfe)
X-HTTP-Via: 1.1 wwwproxy-son-ca-01.ca.sandia.gov:80 (squid/2.5.STABLE14)
Xref: news.mathworks.com comp.soft-sys.matlab:556107


On Jul 16, 2:13 pm, "Matt Fig" <spama...@yahoo.com> wrote:
> I can see no difference in speed (nan vs. inf), but Matt's solution is incomplete as I understand the problem.
>
> % Data
> N = 1200;
> A = round(rand(N)*20);
> B = randperm(N);
>
> % obvious engine.
> tic
> for ii = N:-1:1
>    C(ii,1) = min(A(ii,1:B(ii)));  % OP wants column vector.
> end
> toc
>
> % faster engine for this data.
> tic
> for ii = N:-1:1
>     m = A(ii);
>     for jj = 1:B(ii)
>         if A(ii,jj)<m
>             m = A(ii,jj);
>         end
>     end
>    C2(ii,1) = m;
> end
> toc
>
> % Unfinished(?) engine.
> tic
> Amod = A;
> Amod( bsxfun(@lt,B,(1:N)) ) = nan;
> c = min(Amod,[],2);
> toc
>
> whos
> isequal(C,C2)  % Yes
> isequal(C,c)  % No

The last engine does work. B is supposed to be nx1, not 1xn
: )
But yeah, your for loop is faster than the obvious one.
-Nathan