<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/156151</link>
    <title>MATLAB Central Newsreader - Callbaks, Passing by reference, setting output</title>
    <description>Feed for thread: Callbaks, Passing by reference, setting output</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>Fri, 14 Sep 2007 10:01:49 -0400</pubDate>
      <title>Callbaks, Passing by reference, setting output</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/156151#392299</link>
      <author>Karl Trumstedt</author>
      <description>Hi,&lt;br&gt;
&lt;br&gt;
I have an textcontrol defining a callback {@function, var1, &lt;br&gt;
var2}&lt;br&gt;
&lt;br&gt;
I want to assign var1 the value of the textbox + the value &lt;br&gt;
of var2. This is no problem, but since matlab passes by &lt;br&gt;
value (?) the values does not change var1. How can I either &lt;br&gt;
pass by reference or define an output with my callback?&lt;br&gt;
&lt;br&gt;
a callback like this:&lt;br&gt;
var1 = function(var1, var2) &lt;br&gt;
&lt;br&gt;
/Karl&lt;br&gt;
Developer @ Lundin Mining AB &lt;br&gt;
&lt;a href=&quot;http://www.lundinmining.com/index.php&quot;&gt;http://www.lundinmining.com/index.php&lt;/a&gt; &lt;br&gt;
Developer @ Auktionshuset Kolonn AB &lt;a href=&quot;http://www.kolonn.se&quot;&gt;http://www.kolonn.se&lt;/a&gt;</description>
    </item>
    <item>
      <pubDate>Fri, 14 Sep 2007 10:11:07 -0400</pubDate>
      <title>Re: Callbaks, Passing by reference, setting output</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/156151#392303</link>
      <author>Karl Trumstedt</author>
      <description>I made a temporary solution by passing the name of the &lt;br&gt;
variable to the function and using eval to assign the value.&lt;br&gt;
Since I am using nested function this works, but I am still &lt;br&gt;
interested in other solutions. &lt;br&gt;
&lt;br&gt;
Cheers&lt;br&gt;
/Karl&lt;br&gt;
Developer @ Lundin Mining AB &lt;br&gt;
&lt;a href=&quot;http://www.lundinmining.com/index.php&quot;&gt;http://www.lundinmining.com/index.php&lt;/a&gt; &lt;br&gt;
Developer @ Auktionshuset Kolonn AB &lt;a href=&quot;http://www.kolonn.se&quot;&gt;http://www.kolonn.se&lt;/a&gt;</description>
    </item>
    <item>
      <pubDate>Fri, 14 Sep 2007 13:48:18 -0400</pubDate>
      <title>Re: Callbaks, Passing by reference, setting output</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/156151#392325</link>
      <author>John </author>
      <description>You have mentioned the solution yourself - &lt;br&gt;
var1 = function(var1, var2) &lt;br&gt;
&lt;br&gt;
Why did you not use this to return the output from your&lt;br&gt;
callback ?&lt;br&gt;
&lt;br&gt;
If you want to know more about why matlab uses call by&lt;br&gt;
value, read this - &lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/support/solutions/data/1-15SO4.html?solution=1-15SO4&quot;&gt;http://www.mathworks.com/support/solutions/data/1-15SO4.html?solution=1-15SO4&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&quot;Karl Trumstedt&quot; &amp;lt;karltru@gmail.com&amp;gt; wrote in message&lt;br&gt;
&amp;lt;fcdm6c$vk$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I have an textcontrol defining a callback {@function, var1, &lt;br&gt;
&amp;gt; var2}&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I want to assign var1 the value of the textbox + the value &lt;br&gt;
&amp;gt; of var2. This is no problem, but since matlab passes by &lt;br&gt;
&amp;gt; value (?) the values does not change var1. How can I either &lt;br&gt;
&amp;gt; pass by reference or define an output with my callback?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; a callback like this:&lt;br&gt;
&amp;gt; var1 = function(var1, var2) &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; /Karl&lt;br&gt;
&amp;gt; Developer @ Lundin Mining AB &lt;br&gt;
&amp;gt; &lt;a href=&quot;http://www.lundinmining.com/index.php&quot;&gt;http://www.lundinmining.com/index.php&lt;/a&gt; &lt;br&gt;
&amp;gt; Developer @ Auktionshuset Kolonn AB &lt;a href=&quot;http://www.kolonn.se&quot;&gt;http://www.kolonn.se&lt;/a&gt;</description>
    </item>
    <item>
      <pubDate>Fri, 14 Sep 2007 14:05:07 -0400</pubDate>
      <title>Re: Callbaks, Passing by reference, setting output</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/156151#392328</link>
      <author>Malcolm Lidierth</author>
      <description>Pass the handle of the text box and have the callback read &lt;br&gt;
the text e.g.&lt;br&gt;
&lt;br&gt;
var1=text(0.1,0.1,'MyText');&lt;br&gt;
var2=pi;&lt;br&gt;
set(obj,'Callback', {@myCallback, var1, var2})&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
function(hObj, EventData, var1, var2)&lt;br&gt;
str=get(var1,'String');&lt;br&gt;
.&lt;br&gt;
.&lt;br&gt;
.&lt;br&gt;
end</description>
    </item>
    <item>
      <pubDate>Fri, 14 Sep 2007 14:29:33 -0400</pubDate>
      <title>Re: Callbaks, Passing by reference, setting output</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/156151#392336</link>
      <author>Karl Trumstedt</author>
      <description>I have defined the callback like this&lt;br&gt;
&lt;br&gt;
'Callback', {@functionname, var1, var2}&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
function functionname(hObject, eventdata, var1, var2)&lt;br&gt;
value = str2double(get(hObject, 'String'))&lt;br&gt;
var1 = value + var2;&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
So this function is supposed to assign the value of the &lt;br&gt;
caller and var2 to the variable var1 which exists in the &lt;br&gt;
main function.&lt;br&gt;
&lt;br&gt;
'Callback', var1 = {@functionname, var1, var2}&lt;br&gt;
does not seem to work.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
/Karl&lt;br&gt;
Developer @ Lundin Mining AB &lt;br&gt;
&lt;a href=&quot;http://www.lundinmining.com/index.php&quot;&gt;http://www.lundinmining.com/index.php&lt;/a&gt; &lt;br&gt;
Developer @ Auktionshuset Kolonn AB &lt;a href=&quot;http://www.kolonn.se&quot;&gt;http://www.kolonn.se&lt;/a&gt;</description>
    </item>
    <item>
      <pubDate>Fri, 14 Sep 2007 16:23:53 -0400</pubDate>
      <title>Re: Callbaks, Passing by reference, setting output</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/156151#392360</link>
      <author>Malcolm Lidierth</author>
      <description>I see the problem.&lt;br&gt;
&lt;br&gt;
By their nature, callbacks can not have left-hand side &lt;br&gt;
arguments.&lt;br&gt;
&lt;br&gt;
You need to pass your answer back another way e.g. by &lt;br&gt;
putting it in the user data area of the text object from &lt;br&gt;
the callback:&lt;br&gt;
&lt;br&gt;
set(hObject,'UserData',value+var2)&lt;br&gt;
&lt;br&gt;
then use the appropriate get method in your main code. &lt;br&gt;
&lt;br&gt;
Then of course you need to get your code to hang up until &lt;br&gt;
the callback has done it job (see uiwait and uiresume).</description>
    </item>
  </channel>
</rss>

