Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Column Index
Date: Wed, 1 Jul 2009 22:46:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 25
Message-ID: <h2gov9$gjh$1@fred.mathworks.com>
References: <h2ghmp$t3a$1@fred.mathworks.com> <h2gnm1$o91$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1246488361 17009 172.30.248.35 (1 Jul 2009 22:46:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 1 Jul 2009 22:46:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1886545
Xref: news.mathworks.com comp.soft-sys.matlab:552228


"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <h2gnm1$o91$1@fred.mathworks.com>...
> "Oleg Komarov" <oleg.komarov@hotmail.it> wrote in message <h2ghmp$t3a$1@fred.mathworks.com>...
> > I have a matrix like this:
> > a = random('bino',1,0.5,[10,5]);
> > 
> > And i want to find the colum index corresponding to the last 1 of each row:
> > IDX = NaN(size(a,1),1);
> > for i = 1:size(a,1)
> >     IDX(i) = find(a(i,:),1,'last');
> > end
> > 
> 
> Using SplitVec on FEX http://www.mathworks.com/matlabcentral/fileexchange/24255
> 
> IDX = NaN(size(a,1),1);
> 
> [J I]=find(a.');
> last=SplitVec([I J],1,'last'); % On FEX
> IDX(I(last)) = J(last)
> 
> % Bruno
Thank you very much Jos and Bruno

TO: Jos
I work with matrices which, by construction, in every row have at least one "1".