Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Substitute values in data array
Date: Wed, 4 Nov 2009 12:55:05 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 21
Message-ID: <hcrtj9$6er$1@fred.mathworks.com>
References: <hcrq6d$mn1$1@fred.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
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 1257339305 6619 172.30.248.37 (4 Nov 2009 12:55:05 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 4 Nov 2009 12:55:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:582347


"Florian" <f.pappenberger@NOSPAMlancater.ac.uk> wrote in message <hcrq6d$mn1$1@fred.mathworks.com>...
> Dear all,
> I want to substitute values in data array and there is a matlab function in the toolbox called changem to o so. 
> However, this function uses a loop:
> 
> for k = 1:numel(newval)
>     B(A == oldval(k)) = newval(k);
> end
> 

Careful if oldval and newval intersect and arranged in the order that can fail your for-loop.

A=ceil(10*rand(1,12))
oldval=[1 2];
newval=-oldval

B = A;
[tf k]=ismember(A,oldval);
B(tf)=newval(k(tf))

Bruno