<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264957</link>
    <title>MATLAB Central Newsreader - Substitute values in data array</title>
    <description>Feed for thread: Substitute values in data array</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, 04 Nov 2009 11:57:01 -0500</pubDate>
      <title>Substitute values in data array</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264957#692007</link>
      <author>Florian </author>
      <description>Dear all,&lt;br&gt;
I want to substitute values in data array and there is a matlab function in the toolbox called changem to o so. &lt;br&gt;
However, this function uses a loop:&lt;br&gt;
&lt;br&gt;
for k = 1:numel(newval)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;B(A == oldval(k)) = newval(k);&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
and my array is very large. I have tried to speed it up several ways, but no success. Does anyone have an idea how this could be done faster?&lt;br&gt;
&lt;br&gt;
cheers,&lt;br&gt;
flo</description>
    </item>
    <item>
      <pubDate>Wed, 04 Nov 2009 12:37:02 -0500</pubDate>
      <title>Re: Substitute values in data array</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264957#692013</link>
      <author>Jan Simon</author>
      <description>Dear Florian!&lt;br&gt;
&lt;br&gt;
&amp;gt; I want to substitute values in data array and there is a matlab function in the toolbox called changem to o so. &lt;br&gt;
&amp;gt; However, this function uses a loop:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; for k = 1:numel(newval)&lt;br&gt;
&amp;gt;     B(A == oldval(k)) = newval(k);&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; and my array is very large.&lt;br&gt;
&lt;br&gt;
Please specify the sizes auf B, A, newval.&lt;br&gt;
&lt;br&gt;
&amp;gt; I have tried to speed it up several ways, but no success. Does anyone have an idea how this could be done faster?&lt;br&gt;
&lt;br&gt;
Please tell us, what you have tried already. Then we do not have to try it again...&lt;br&gt;
&lt;br&gt;
Sometimes FINDSTR is faster than the == operator.&lt;br&gt;
Are there repititions in oldval/newval?&lt;br&gt;
Have you tried to use backwar-indexing (e.g. X(oldval)=newval; B = X(A);), as e.g. in IND2RGB?&lt;br&gt;
&lt;br&gt;
Good luck, Jan</description>
    </item>
    <item>
      <pubDate>Wed, 04 Nov 2009 12:55:05 -0500</pubDate>
      <title>Re: Substitute values in data array</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264957#692017</link>
      <author>Bruno Luong</author>
      <description>&quot;Florian&quot; &amp;lt;f.pappenberger@NOSPAMlancater.ac.uk&amp;gt; wrote in message &amp;lt;hcrq6d$mn1$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Dear all,&lt;br&gt;
&amp;gt; I want to substitute values in data array and there is a matlab function in the toolbox called changem to o so. &lt;br&gt;
&amp;gt; However, this function uses a loop:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; for k = 1:numel(newval)&lt;br&gt;
&amp;gt;     B(A == oldval(k)) = newval(k);&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
Careful if oldval and newval intersect and arranged in the order that can fail your for-loop.&lt;br&gt;
&lt;br&gt;
A=ceil(10*rand(1,12))&lt;br&gt;
oldval=[1 2];&lt;br&gt;
newval=-oldval&lt;br&gt;
&lt;br&gt;
B = A;&lt;br&gt;
[tf k]=ismember(A,oldval);&lt;br&gt;
B(tf)=newval(k(tf))&lt;br&gt;
&lt;br&gt;
Bruno</description>
    </item>
    <item>
      <pubDate>Wed, 04 Nov 2009 13:49:02 -0500</pubDate>
      <title>Re: Substitute values in data array</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264957#692035</link>
      <author>Florian </author>
      <description>Bruno,&lt;br&gt;
thanks that works - you should submit that also to mathworks as a replacement for changem .m :-)&lt;br&gt;
&lt;br&gt;
Thanks a lot!!!!!&lt;br&gt;
flo</description>
    </item>
  </channel>
</rss>

