<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/254606</link>
    <title>MATLAB Central Newsreader - Operate on certain element</title>
    <description>Feed for thread: Operate on certain element</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Wed, 24 Jun 2009 22:04:01 -0400</pubDate>
      <title>Operate on certain element</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/254606#660282</link>
      <author>Diego Lass</author>
      <description>Hi,&lt;br&gt;
I want to operate on certain elements in a vector, but leave other elements intact.  &lt;br&gt;
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?&lt;br&gt;
&lt;br&gt;
In another words, how to single out the indexes, so I can do operation only on these?&lt;br&gt;
&lt;br&gt;
Thanks&lt;br&gt;
Diego </description>
    </item>
    <item>
      <pubDate>Wed, 24 Jun 2009 22:18:01 -0400</pubDate>
      <title>Re: Operate on certain element</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/254606#660287</link>
      <author>Alan B</author>
      <description>&quot;Diego Lass&quot; &amp;lt;dlISCool@gmail.com&amp;gt; wrote in message &amp;lt;h1u7sh$2e7$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt; I want to operate on certain elements in a vector, but leave other elements intact.  &lt;br&gt;
&amp;gt; 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?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; In another words, how to single out the indexes, so I can do operation only on these?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks&lt;br&gt;
&amp;gt; Diego &lt;br&gt;
&lt;br&gt;
How about this?&lt;br&gt;
&lt;br&gt;
change = setdiff(1:length(A), dontchange);&lt;br&gt;
B = A; &lt;br&gt;
B(change) = f(A(change));</description>
    </item>
    <item>
      <pubDate>Thu, 25 Jun 2009 14:06:41 -0400</pubDate>
      <title>Re: Operate on certain element</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/254606#660420</link>
      <author>Steven Lord</author>
      <description>&lt;br&gt;
&quot;Alan B&quot; &amp;lt;monguin61@yahoo.com&amp;gt; wrote in message &lt;br&gt;
news:h1u8mp$nr5$1@fred.mathworks.com...&lt;br&gt;
&amp;gt; &quot;Diego Lass&quot; &amp;lt;dlISCool@gmail.com&amp;gt; wrote in message &lt;br&gt;
&amp;gt; &amp;lt;h1u7sh$2e7$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt;&amp;gt; Hi,&lt;br&gt;
&amp;gt;&amp;gt; I want to operate on certain elements in a vector, but leave other &lt;br&gt;
&amp;gt;&amp;gt; elements intact.&lt;br&gt;
&amp;gt;&amp;gt; Say I know the indexes that I don't want to change, but don't know the &lt;br&gt;
&amp;gt;&amp;gt; indexes I want to change(is the complement of the ones I don't want to &lt;br&gt;
&amp;gt;&amp;gt; change).  What is the most efficient way to do this?&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; In another words, how to single out the indexes, so I can do operation &lt;br&gt;
&amp;gt;&amp;gt; only on these?&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; Thanks&lt;br&gt;
&amp;gt;&amp;gt; Diego&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; How about this?&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; change = setdiff(1:length(A), dontchange);&lt;br&gt;
&amp;gt; B = A;&lt;br&gt;
&amp;gt; B(change) = f(A(change));&lt;br&gt;
&lt;br&gt;
That's one way to do it, although to handle the case where A is a matrix &lt;br&gt;
you'd want to use NUMEL instead of LENGTH in your first line.  Alternately, &lt;br&gt;
use logical indexing instead of linear:&lt;br&gt;
&lt;br&gt;
elementsToChange = true(size(A));&lt;br&gt;
elementToChange(dontchange) = false;&lt;br&gt;
B = A;&lt;br&gt;
B(elementsToChange) = f(A(elementsToChange));&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
Steve Lord&lt;br&gt;
slord@mathworks.com </description>
    </item>
    <item>
      <pubDate>Thu, 25 Jun 2009 15:17:01 -0400</pubDate>
      <title>Re: Operate on certain element</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/254606#660439</link>
      <author>Matt </author>
      <description>&quot;Alan B&quot; &amp;lt;monguin61@yahoo.com&amp;gt; wrote in message &amp;lt;h1u8mp$nr5$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&lt;br&gt;
&amp;gt; change = setdiff(1:length(A), dontchange);&lt;br&gt;
&lt;br&gt;
Using setdiff() invokes unnecessary sorting operations. &lt;br&gt;
&lt;br&gt;
Steve's method is probably the optimal one , but if you really do need to compute &quot;change&quot; as a set of linear indices, this would probably be better than using setdiff:&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
change=1:numel(A);&lt;br&gt;
change(dontchange)=[];</description>
    </item>
  </channel>
</rss>

