Path: news.mathworks.com!newsfeed-00.mathworks.com!kanaga.switch.ch!switch.ch!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsfeed.straub-nv.de!feeder.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Yet another Vectorization Question
Date: Wed, 17 Feb 2010 15:49:18 -0600
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <hlhob3$qde$1@news.eternal-september.org>
References: <hlhk42$s84$1@fred.mathworks.com> <hlhl7p$7k1$1@news.eternal-september.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 17 Feb 2010 21:50:28 +0000 (UTC)
Injection-Info: feeder.eternal-september.org; posting-host="HPc9+psV10hKjoxF94WmXA";
	logging-data="27054"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+W0J5HrjGJXb3mgxYJvyWr"
User-Agent: Thunderbird 2.0.0.23 (Windows/20090812)
In-Reply-To: <HIDDEN>
Cancel-Lock: sha1:JoiXYnz+OJ6FV3FCxgX3QekskO0=
Xref: news.mathworks.com comp.soft-sys.matlab:609046

dpb wrote:
> Susan wrote:
>> Does anyone have any thoughts on speeding up the following code?
>>
>> Thanks!
>> Susan
>> -------------------------------------------------
>> function ix = findfirstinrow( boolMat )
>>
>> ix = zeros(size(boolMat,1),1);
>>
>> for row = 1:size(boolMat,1)
>>  for col = size(boolMat,2)
>>    ix(row) = find(boolMat(row,:),1);
>>  end
>> end
> 
> Why the loop on col; nothing is dependent on it???
> 
> But, what's wrong w/
> 
> function ix = findfirstinrow( x )
>   ix = zeros(size(x,1),1);
>   [r,c] = find(x,1,'first');
>   ix(r) = 1;

Oh, I guess it's

ix(r)=c;

that you want, isn't it?

--