Force MATLAB to run a specific function.
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I understand MATLAB has an order of precedence for resolving names and that this can be useful in overriding the behavior of a MATLAB function. For example one can create a subfunction called sin that runs when called from within the main function instead of the builtin sin function. By the same token you can create a subfunction called fzero that runs instead of the supplied fzero function. In the case were I have a subfunction with the same name as a built-in function I can force MATLAB to run the builtin by using the 'builtin('function,x1,x1...) command. However, how to I do this with supplied functions such as fzero?
In short is there a way to force MATLAB to ignore the search path and run the function in a specific folder?
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 4 Jun. 2012
function varargout = fevalin(path, varargin)
oldfolder = cd(path);
[varargout{:}] = feval(varargin{:});
cd(oldfolder);
end
But with added sanity tests. And remember to cd back if you catch an error.
2 Kommentare
Walter Roberson
am 4 Jun. 2012
Yes, the syntax is an extension of feval()
I realized last night that this does not do exactly what you asked. When you use this or equivalent (e.g., manipulate the MATLAB path) then if the function calls a second function that you have loaded, then because the path has changed, the non-overloaded version would be called, whereas to be consistent the overloaded function should be called since the dispatching should affect *only* the named function and not anything else. I might be able to get around that if it is important.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Variables finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!