I have several large matrices that should be passed to different functions many times in an iterative algorithm. How can I avoid the unnecessary copy of variables to the function to speed up the program? Is there any way to group these matrices in a structure or class and pass them by reference or pointer?
a=zeros(1000,1000);
b=zeros(1000,1000);
d=myfunction(a,b);
a=myfunction2(b,d);
....
Thanks.
Update: I should have provided more details as I see in the comments. I have several large matrices. Few of them remain constant in the program and others change in each function at each iteration. So if I pass these matrices by value, Matlab makes a copy of that, changes the value and again copy them as the output of the function and then they go out of scope and get destroyed and at each iteration all these unnecessary copying make the program awfully slow. If I were to program it in C++, I would use object oriented programming for these matrices and I would pass them as reference to the function but I don't know if that's possible in MATLAB.