Can MATLAB pass by reference?
373 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Doug Hull
am 18 Jan. 2011
Kommentiert: Yorgos Tsitsikas
am 15 Sep. 2023
How does MATLAB deal with this?
1 Kommentar
Akzeptierte Antwort
Doug Hull
am 18 Jan. 2011
7 Kommentare
Bill Tubbs
am 22 Okt. 2021
Both the links in the answer seem to be broken now. Does anybody have updated URLs?
Is this one of them perhaps:
Yorgos Tsitsikas
am 15 Sep. 2023
Weitere Antworten (4)
Marco
am 18 Jul. 2012
Is this also true for nested function calls? Cuz it seems like it only works for direct function calls. In my GUIDE gui I have a function (call it Fn_takesHandles) that takes in the figure handles and updates the axes, when called by callback functions directly works just as intended. However, I run into problems when the stack frame is not one-to-one. A callBack function calls a helper function called Auto which in turn calls Fn_takesHandles. In this case it does not work as intended. Any changes made to the figure handles by Fn_takesHandles is not persistent. How would you go about solving this problem?
Is there any way to declare pointers in matlab? Any help would be appreciated!!
1 Kommentar
Walter Roberson
am 19 Jul. 2012
Bearbeitet: Walter Roberson
am 14 Sep. 2018
There is no way to declare pointers in MATLAB (at least not for calling MATLAB functions; there are ways to copy around pointers that have been created at the C / C++ level.)
Jason Climer
am 20 Jun. 2017
Is this determined during the JIT compilation or as needed, i.e., is the copy of x made upon the function call or when the program executes
x(2) = 2;
?
1 Kommentar
Walter Roberson
am 20 Jun. 2017
It is generally determined when the program executes, as it is not always possible to tell ahead of time whether a value is shared or not. Especially when you consider the hidden effect of assignin() .
Also, overloading can happen at run-time: the current directory or path of an operation at the time a routine is first JIT'd is not necessarily going to be the same as during a later operation.
There are cases where MATLAB does enough analysis to establish that "update in place" can happen; I do not know enough about the mechanics of that to say how it is done taking into account overloading.
Mandeguz
am 22 Jun. 2017
How about when writing MEXs? Can one pass by reference within the computational routine and pull those values back to the main MATLAB code that called the MEX?
4 Kommentare
James Tursa
am 14 Sep. 2018
Also note that as of R2015b, MATLAB passes arguments to mex routines as shared data copies (it used to pass them by reference).
James Tursa
am 10 Jan. 2019
And as of R2018a, complex variable arguments to mex routines essentially get deep data copied in both directions if you use the -R2017a compilation model.
Siehe auch
Kategorien
Mehr zu Whos finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!