The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Still want Call-by-reference
Replies: 3   Last Post: Jun 4, 1997 5:19 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Chuck Anderson

Posts: 2
Registered: 12/7/04
Still want Call-by-reference
Posted: May 29, 1997 10:19 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Thanks for the quick reply from Mathworks to my question about
call-by-reference. Yes, I am working in Matlab 5. The reply did help
clarify the concern about when new copies of data structures are made.
However, I guess what I need will have to wait for future
enhancements. Here is a simple example of what I'd like to do:

Here is a function:

function changea(s)
for i = 1:1000
s.a(i) = i*10;

I'd like to be able to call it using

s.a = ones(1,1000);
s.b = zeros(1,2000);

and now have the elements of s.a(i) all be their new values that were
set inside of changea. Currently, Matlab will allocate memory for a
new copy of s.a as soon as one element is changed, right? If there
were someway of specifying that I don't want components of s to be
copied, then a lot of memory allocating would be avoided. The
1,000-element array in s.a would not have to be reallocated.

I suppose one solution to this is to code the function changea as a
cmex function. I prefer the flexibility of the Matlab programming
environment, so consider this a very strong vote for including this
capability in the next revisions to Matlab.

Chuck Anderson
Department of Computer Science
Colorado State University
Fort Collins, CO 80523-1873 office: 970-491-7491, FAX: 970-491-2466

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.