<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/167431</link>
    <title>MATLAB Central Newsreader - call by reference</title>
    <description>Feed for thread: call by reference</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>Sat, 12 Apr 2008 09:33:27 -0400</pubDate>
      <title>call by reference</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/167431#426208</link>
      <author>Jeroen</author>
      <description>Hi all,&lt;br&gt;
&lt;br&gt;
For some GPS related calculations, I have a bunch of vectors  and variables which are needed in a lot of functions.&lt;br&gt;
&lt;br&gt;
The thing is that all those date belong togehter in some way. When I would program in Jave, I would make a class from it.&lt;br&gt;
&lt;br&gt;
So, what I did is making a new matlab data type which bundles all this information. I added some functions such that it acts just as a struct: I can acces the columns and the elements. The nice advantage is that I could modify the display function, such that I get a nice overview of the data when omitting the ;&lt;br&gt;
&lt;br&gt;
But, when I pass this data type as argument to a function, do some manipulations on it, and want the function to return it, it slows down my program due to call by value.&lt;br&gt;
&lt;br&gt;
Is there a way to work with pointers and adresses like is possible in C? Or is there perhaps another solution for my problem?&lt;br&gt;
&lt;br&gt;
All hints are really appreciated!&lt;br&gt;
&lt;br&gt;
Many thanks,&lt;br&gt;
J.</description>
    </item>
    <item>
      <pubDate>Sat, 12 Apr 2008 10:25:03 -0400</pubDate>
      <title>Re: call by reference</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/167431#426212</link>
      <author>Bruno Luong</author>
      <description>Jeroen &amp;lt;jverhoeve@hotmail.com&amp;gt; wrote in message&lt;br&gt;
&amp;lt;8902033.1207992837734.JavaMail.jakarta@nitrogen.mathforum.org&amp;gt;...&lt;br&gt;
&amp;gt; Hi all,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; For some GPS related calculations, I have a bunch of&lt;br&gt;
vectors  and variables which are needed in a lot of functions.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; The thing is that all those date belong togehter in some&lt;br&gt;
way. When I would program in Jave, I would make a class from it.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; So, what I did is making a new matlab data type which&lt;br&gt;
bundles all this information. I added some functions such&lt;br&gt;
that it acts just as a struct: I can acces the columns and&lt;br&gt;
the elements. The nice advantage is that I could modify the&lt;br&gt;
display function, such that I get a nice overview of the&lt;br&gt;
data when omitting the ;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; But, when I pass this data type as argument to a function,&lt;br&gt;
do some manipulations on it, and want the function to return&lt;br&gt;
it, it slows down my program due to call by value.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Is there a way to work with pointers and adresses like is&lt;br&gt;
possible in C? Or is there perhaps another solution for my&lt;br&gt;
problem?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; All hints are really appreciated!&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Many thanks,&lt;br&gt;
&amp;gt; J.&lt;br&gt;
&lt;br&gt;
&quot;Inplace&quot; package in FEX might be what you are looking for:&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=11290&amp;objectType=file&quot;&gt;http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=11290&amp;objectType=file&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
Warning: reference argument passing is not supported by&lt;br&gt;
Mathworks, and they do anything to discourage users to use them.&lt;br&gt;
&lt;br&gt;
Bruno</description>
    </item>
    <item>
      <pubDate>Sat, 12 Apr 2008 10:38:24 -0400</pubDate>
      <title>Re: call by reference</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/167431#426213</link>
      <author>Jeroen</author>
      <description>Thanks Bruno,&lt;br&gt;
&lt;br&gt;
This solves one of the two problems:&lt;br&gt;
- call by reference&lt;br&gt;
&lt;br&gt;
The other one remains:&lt;br&gt;
- how to keep data bundled (I do it by defining my own data type) together and pass it in a time economic way as an argument.&lt;br&gt;
&lt;br&gt;
Note: My data type consists of 10 vectors of 30 elements, together with some variables.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
The package you suggest can only work with vectors and matrices, while I want to pass my own defined data types by reference.</description>
    </item>
    <item>
      <pubDate>Sat, 12 Apr 2008 11:53:01 -0400</pubDate>
      <title>Re: call by reference</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/167431#426227</link>
      <author>Bruno Luong</author>
      <description>Jeroen &amp;lt;jverhoeve@hotmail.com&amp;gt; wrote in message&lt;br&gt;
&amp;lt;8672860.1207996734521.JavaMail.jakarta@nitrogen.mathforum.org&amp;gt;...&lt;br&gt;
&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; The package you suggest can only work with vectors and&lt;br&gt;
matrices, while I want to pass my own defined data types by&lt;br&gt;
reference.&lt;br&gt;
&lt;br&gt;
MATLAB engine has a smart mechanism that avoids to duplicate&lt;br&gt;
data when it is not necessary, even when passing parameter&lt;br&gt;
by value. The only (?) data type that requires a large&lt;br&gt;
amount of (contiguous) memory and needed to be duplicate&lt;br&gt;
entirely when a element is changed is array. That's why the&lt;br&gt;
inplace FEX program works on array.&lt;br&gt;
&lt;br&gt;
You might want to pass your structure object as value, and&lt;br&gt;
use inplace for subfields that are big arrays.&lt;br&gt;
&lt;br&gt;
Otherwise you might have to program your own mex function&lt;br&gt;
with (structure) parameters passing as reference.&lt;br&gt;
&lt;br&gt;
Please see the recent thread for various opinions and&lt;br&gt;
informations:&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/matlabcentral/newsreader/view_thread/163743&quot;&gt;http://www.mathworks.com/matlabcentral/newsreader/view_thread/163743&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
Bruno</description>
    </item>
    <item>
      <pubDate>Sat, 12 Apr 2008 19:10:06 -0400</pubDate>
      <title>Re: call by reference</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/167431#426269</link>
      <author>Stuart McGarrity</author>
      <description>Jeroen &amp;lt;jverhoeve@hotmail.com&amp;gt; wrote in message &lt;br&gt;
&amp;lt;8902033.1207992837734.JavaMail.jakarta@nitrogen.mathforum.&lt;br&gt;
org&amp;gt;...&lt;br&gt;
&amp;gt; Hi all,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; For some GPS related calculations, I have a bunch of &lt;br&gt;
vectors  and variables which are needed in a lot of &lt;br&gt;
functions.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; The thing is that all those date belong togehter in some &lt;br&gt;
way. When I would program in Jave, I would make a class &lt;br&gt;
from it.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; So, what I did is making a new matlab data type which &lt;br&gt;
bundles all this information. I added some functions such &lt;br&gt;
that it acts just as a struct: I can acces the columns and &lt;br&gt;
the elements. The nice advantage is that I could modify &lt;br&gt;
the display function, such that I get a nice overview of &lt;br&gt;
the data when omitting the ;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; But, when I pass this data type as argument to a &lt;br&gt;
function, do some manipulations on it, and want the &lt;br&gt;
function to return it, it slows down my program due to &lt;br&gt;
call by value.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Is there a way to work with pointers and adresses like &lt;br&gt;
is possible in C? Or is there perhaps another solution for &lt;br&gt;
my problem?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; All hints are really appreciated!&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Many thanks,&lt;br&gt;
&amp;gt; J.&lt;br&gt;
I recommend you take a look at:&lt;br&gt;
1) Specifying reference behaviour with handle classes in &lt;br&gt;
R2008a:&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/access/helpdesk/help/techdoc/matla&quot;&gt;http://www.mathworks.com/access/helpdesk/help/techdoc/matla&lt;/a&gt;&lt;br&gt;
b_oop/brfylwk-1.html&lt;br&gt;
&lt;br&gt;
2)How MATLAB's copy-on-write behaviour for value objects &lt;br&gt;
works:&lt;br&gt;
&lt;a href=&quot;http://blogs.mathworks.com/loren/2006/05/10/memory-&quot;&gt;http://blogs.mathworks.com/loren/2006/05/10/memory-&lt;/a&gt;&lt;br&gt;
management-for-functions-and-variables/&lt;br&gt;
&lt;br&gt;
3)In-place calling behaviour:&lt;br&gt;
&lt;a href=&quot;http://blogs.mathworks.com/loren/2007/03/22/in-place-&quot;&gt;http://blogs.mathworks.com/loren/2007/03/22/in-place-&lt;/a&gt;&lt;br&gt;
operations-on-data/&lt;br&gt;
&lt;br&gt;
Stuart</description>
    </item>
    <item>
      <pubDate>Mon, 14 Apr 2008 13:47:06 -0400</pubDate>
      <title>Re: call by reference</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/167431#426494</link>
      <author>Peter Boettcher</author>
      <description>Jeroen &amp;lt;jverhoeve@hotmail.com&amp;gt; writes:&lt;br&gt;
&lt;br&gt;
&amp;gt; Hi all,&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; For some GPS related calculations, I have a bunch of vectors and&lt;br&gt;
&amp;gt; variables which are needed in a lot of functions.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; The thing is that all those date belong togehter in some way. When I&lt;br&gt;
&amp;gt; would program in Jave, I would make a class from it.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; So, what I did is making a new matlab data type which bundles all this&lt;br&gt;
&amp;gt; information. I added some functions such that it acts just as a&lt;br&gt;
&amp;gt; struct: I can acces the columns and the elements. The nice advantage&lt;br&gt;
&amp;gt; is that I could modify the display function, such that I get a nice&lt;br&gt;
&amp;gt; overview of the data when omitting the ;&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; But, when I pass this data type as argument to a function, do some&lt;br&gt;
&amp;gt; manipulations on it, and want the function to return it, it slows down&lt;br&gt;
&amp;gt; my program due to call by value.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Is there a way to work with pointers and adresses like is possible in&lt;br&gt;
&amp;gt; C? Or is there perhaps another solution for my problem?&lt;br&gt;
&lt;br&gt;
The only reason I would pursue in-place computation is if you have a&lt;br&gt;
very large dataset, in the hundreds of megabytes.  Otherwise, I would&lt;br&gt;
guess that a simple struct array passed in and out of your functions&lt;br&gt;
will do fine.&lt;br&gt;
&lt;br&gt;
MATLAB already makes use of call-by-reference, internally, when a&lt;br&gt;
variable (or part of a cell or struct array) is not modified.  How have&lt;br&gt;
you determined that call-by-value is the particular cause of your&lt;br&gt;
performance problem?&lt;br&gt;
&lt;br&gt;
-Peter</description>
    </item>
    <item>
      <pubDate>Mon, 14 Apr 2008 18:07:33 -0400</pubDate>
      <title>Re: call by reference</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/167431#426561</link>
      <author>Jeroen</author>
      <description>Hi,&lt;br&gt;
indeed, it is aldready done by reference&lt;br&gt;
&lt;br&gt;
What I am doing is: &lt;br&gt;
function list = actionOnList(list)&lt;br&gt;
&lt;br&gt;
Since the input argument is the same as the output argument, matlab handles it by reference. This is what I figured out on the internet.&lt;br&gt;
&lt;br&gt;
I am loosing time in another place in the code, which uses extensively if/else statements. This is in an iterative loop, so I set the constraints to quit the loop less strict.&lt;br&gt;
&lt;br&gt;
This solved my performance problem.&lt;br&gt;
&lt;br&gt;
Thanks.</description>
    </item>
  </channel>
</rss>

