Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.



Still want Callbyreference
Posted:
May 29, 1997 10:19 AM


Thanks for the quick reply from Mathworks to my question about callbyreference. 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; end
I'd like to be able to call it using
s.a = ones(1,1000); s.b = zeros(1,2000); changea(s);
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,000element 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 anderson@cs.colostate.edu Colorado State University http://www.cs.colostate.edu/~anderson Fort Collins, CO 805231873 office: 9704917491, FAX: 9704912466



