Force MATLAB to run a specific function.
12 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Walter Roberson
2012 年 6 月 4 日
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 件のコメント
Walter Roberson
2012 年 6 月 4 日
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.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Whos についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!