Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Column Index
Date: Wed, 1 Jul 2009 22:24:01 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 20
Message-ID: <h2gnm1$o91$1@fred.mathworks.com>
References: <h2ghmp$t3a$1@fred.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
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 1246487041 24865 172.30.248.37 (1 Jul 2009 22:24:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 1 Jul 2009 22:24:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:552222


"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