Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Speeding Up Code
Date: Thu, 9 Jun 2011 00:03:04 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 19
Message-ID: <isp2jo$rb$1@newscl01ah.mathworks.com>
References: <isk6s3$r2a$1@newscl01ah.mathworks.com> <islhdo$k9d$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-03-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1307577784 875 172.30.248.48 (9 Jun 2011 00:03:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 9 Jun 2011 00:03:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2905527
Xref: news.mathworks.com comp.soft-sys.matlab:730947

"Roger Stafford" wrote in message <islhdo$k9d$1@newscl01ah.mathworks.com>...
>   The five-line if-else-end sequence involving B1 looks completely misplaced.  It keeps overwriting all its previous computations in the for-loop, so therefore it ought to be done after the for-loop finishes where it would only be performed once.
> 
>   However, there is a function, 'ismember', that can calculate B much more efficiently:
> 
>  [t,B] = ismember(ID,mat1(:,1));
>  B1 = sort(B(t));
> 
> I have interpreted your phrase "I want B1 to be an ordered list" to mean you wanted the B1 indices of B to be in ascending order.  That would not be accomplished in your code.
> 
> Roger Stafford

Hi Roger,

Many thanks for your response! The 'ismember' function is exactly what I was looking for, the code is a lot faster now. Actually I meant that I wanted B1 to be in the order that the numbers occur in 'ID', not in ascending order, so I have just used B1=B(t) instead of B1=sort(B(t)).

Thanks again,

Yvette