Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Properly vectorizing code when using "if"
Date: Sun, 12 Oct 2008 00:54:03 +0000 (UTC)
Organization: Battelle Energy Alliance (INL)
Lines: 14
Message-ID: <gcrhrb$j54$1@fred.mathworks.com>
References: <gcrab9$kns$1@fred.mathworks.com>
Reply-To: <HIDDEN>
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 1223772843 19620 172.30.248.37 (12 Oct 2008 00:54:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 12 Oct 2008 00:54:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 688530
Xref: news.mathworks.com comp.soft-sys.matlab:494731


"Johan " <robert.mchugh@ips.invensys.com> wrote in message <gcrab9$kns$1@fred.mathworks.com>...
Both of these functions are positive in their respective domains. However, the implementation below doesn't work as intended.   
> x = -1:0.01:1;
> r = ifTest(x);
> plot(x,r);
> 



function[x] = ifTest(x)

tmp = x<0;
x(tmp) = x(tmp).^2;
x(~tmp) = x(~tmp).^3