Path: news.mathworks.com!not-for-mail
From: "Phil Goddard" <philgoddardNOSPAM@telus.net>
Newsgroups: comp.soft-sys.matlab
Subject: Re: eval, feval, global
Date: Thu, 27 Mar 2008 11:47:01 +0000 (UTC)
Organization: Goddard Consulting
Lines: 25
Message-ID: <fsg1fl$p8e$1@fred.mathworks.com>
References: <fsebf0$43u$1@fred.mathworks.com> <fsf3ss$e2e$1@fred.mathworks.com> <fsfrld$fep$1@fred.mathworks.com> <fsfuht$e44$1@fred.mathworks.com> <fsg06f$8hh$1@fred.mathworks.com>
Reply-To: "Phil Goddard" <philgoddardNOSPAM@telus.net>
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 1206618421 25870 172.30.248.37 (27 Mar 2008 11:47:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 27 Mar 2008 11:47:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 26433
Xref: news.mathworks.com comp.soft-sys.matlab:459453



Although mmrepeat is elegent, for Yuri's test case it is 
almost as slow as Yuri's original (inefficient) loop.

I suspect that timing for this is highly data dependent 
(i.e. depends heavily on the values in the second vector), 
however for me (and Yuri's test case) the following loop 
significantly beats all curently proposed approaches:

%%%%%%% Cut here
function c = construct_array4(a,b)

eIdx = cumsum(b);
sIdx = [1 eIdx(1:end-1)+1];

c = nan(1,eIdx(end));
for idx = 1:length(eIdx)
    c(sIdx(idx):eIdx(idx)) = a(idx);
end
%%%%%%% Cut here

However, the bottom line is still that EVAL can and should 
be avoided.

Phil.