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$>
References: <isk6s3$r2a$> <islhdo$k9d$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1307577784 875 (9 Jun 2011 00:03:04 GMT)
NNTP-Posting-Date: Thu, 9 Jun 2011 00:03:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2905527
Xref: comp.soft-sys.matlab:730947

"Roger Stafford" wrote in message <islhdo$k9d$>...
>   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,