Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Column Index
Date: Wed, 1 Jul 2009 20:42:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 14
Message-ID: <h2ghmp$t3a$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 1246480921 29802 172.30.248.38 (1 Jul 2009 20:42:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 1 Jul 2009 20:42:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1886545
Xref: news.mathworks.com comp.soft-sys.matlab:552184


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

Can it be done without the loop?

Thanks a lot

Oleg