Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Simple matrix manipulation question
Date: Thu, 16 Jul 2009 20:23:01 +0000 (UTC)
Organization: Xoran Technologies
Lines: 12
Message-ID: <h3o275$2h9$1@fred.mathworks.com>
References: <h3lt89$b6e$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1247775781 2601 172.30.248.37 (16 Jul 2009 20:23:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 16 Jul 2009 20:23:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1440443
Xref: news.mathworks.com comp.soft-sys.matlab:556083


"jcurr Curran" <johncurran20@yahoo.com> wrote in message <h3lt89$b6e$1@fred.mathworks.com>...
> Hi all,
> 
> Suppose I have a n x k matrix A and a n x 1 column vector b. b contains integers between 1 and k. I want to produce a n x 1 column vector c, which is defined by c(i) = min {A(i,1),A(i,2),...,A(i,b(i)}. This would be easy with loops, but I want code which will run as fast as possible (the matrices are large, and the operation will be performed many times).
-------

Another option


Amod=A;
Amod( bsxfun(@lt,b,(1:k)) )=nan;
c=min(Amod,[],2);