call by reference

  • Follow


Hi all,

For some GPS related calculations, I have a bunch of vectors  and variables which are needed in a lot of functions.

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.

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 ;

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.

Is there a way to work with pointers and adresses like is possible in C? Or is there perhaps another solution for my problem?

All hints are really appreciated!

Many thanks,
J.
0
Reply jverhoeve (3) 4/12/2008 5:33:27 AM

Jeroen <jverhoeve@hotmail.com> wrote in message
<8902033.1207992837734.JavaMail.jakarta@nitrogen.mathforum.org>...
> Hi all,
> 
> For some GPS related calculations, I have a bunch of
vectors  and variables which are needed in a lot of functions.
> 
> 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.
> 
> 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 ;
> 
> 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.
> 
> Is there a way to work with pointers and adresses like is
possible in C? Or is there perhaps another solution for my
problem?
> 
> All hints are really appreciated!
> 
> Many thanks,
> J.

"Inplace" package in FEX might be what you are looking for:
http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=11290&objectType=file

Warning: reference argument passing is not supported by
Mathworks, and they do anything to discourage users to use them.

Bruno
0
Reply b.luong (628) 4/12/2008 10:25:03 AM


Jeroen <jverhoeve@hotmail.com> wrote in message 
<8902033.1207992837734.JavaMail.jakarta@nitrogen.mathforum.
org>...
> Hi all,
> 
> For some GPS related calculations, I have a bunch of 
vectors  and variables which are needed in a lot of 
functions.
> 
> 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.
> 
> 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 ;
> 
> 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.
> 
> Is there a way to work with pointers and adresses like 
is possible in C? Or is there perhaps another solution for 
my problem?
> 
> All hints are really appreciated!
> 
> Many thanks,
> J.
I recommend you take a look at:
1) Specifying reference behaviour with handle classes in 
R2008a:
http://www.mathworks.com/access/helpdesk/help/techdoc/matla
b_oop/brfylwk-1.html

2)How MATLAB's copy-on-write behaviour for value objects 
works:
http://blogs.mathworks.com/loren/2006/05/10/memory-
management-for-functions-and-variables/

3)In-place calling behaviour:
http://blogs.mathworks.com/loren/2007/03/22/in-place-
operations-on-data/

Stuart
0
Reply stuart.mcgarrity.nospam (19) 4/12/2008 7:10:06 PM

Jeroen <jverhoeve@hotmail.com> writes:

> Hi all,
>
> For some GPS related calculations, I have a bunch of vectors and
> variables which are needed in a lot of functions.
>
> 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.
>
> 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 ;
>
> 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.
>
> Is there a way to work with pointers and adresses like is possible in
> C? Or is there perhaps another solution for my problem?

The only reason I would pursue in-place computation is if you have a
very large dataset, in the hundreds of megabytes.  Otherwise, I would
guess that a simple struct array passed in and out of your functions
will do fine.

MATLAB already makes use of call-by-reference, internally, when a
variable (or part of a cell or struct array) is not modified.  How have
you determined that call-by-value is the particular cause of your
performance problem?

-Peter
0
Reply boettcher (2302) 4/14/2008 1:47:06 PM

3 Replies
82 Views

(page loaded in 0.173 seconds)

Similiar Articles:













7/11/2012 10:13:54 AM


Reply: