Path: news.mathworks.com!not-for-mail
From: "Alan B" <monguin61@yahoo.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Operate on certain element
Date: Wed, 24 Jun 2009 22:18:01 +0000 (UTC)
Organization: UT
Lines: 15
Message-ID: <h1u8mp$nr5$1@fred.mathworks.com>
References: <h1u7sh$2e7$1@fred.mathworks.com>
Reply-To: "Alan B" <monguin61@yahoo.com>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1245881881 24421 172.30.248.38 (24 Jun 2009 22:18:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 24 Jun 2009 22:18:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1446885
Xref: news.mathworks.com comp.soft-sys.matlab:550455


"Diego Lass" <dlISCool@gmail.com> wrote in message <h1u7sh$2e7$1@fred.mathworks.com>...
> Hi,
> I want to operate on certain elements in a vector, but leave other elements intact.  
> Say I know the indexes that I don't want to change, but don't know the indexes I want to change(is the complement of the ones I don't want to change).  What is the most efficient way to do this?
> 
> In another words, how to single out the indexes, so I can do operation only on these?
> 
> Thanks
> Diego 

How about this?

change = setdiff(1:length(A), dontchange);
B = A; 
B(change) = f(A(change));