
Untitled
By: a guest on
May 1st, 2012 | syntax:
None | size: 2.31 KB | hits: 21 | expires: Never
Is it possible to call a function that is not in the path in MATLAB?
builtin('reshape', arg1, arg2, ..., argN);
function runExtended(script,varargin)
cur = cd;
if isempty(script), return, end
if ispc, script(script=='/')=''; end
[p,s,ext] = fileparts(script);
if ~isempty(p),
if exist(p,'dir'),
cd(p)
w = which(s);
if ~isempty(w),
% Check to make sure everything matches
[wp,ws,wext] = fileparts(w);
% Allow users to choose the .m file and run a .p
if strcmp(wext,'.p') && strcmp(ext,'.m'),
wext = '.m';
end
if ispc
cont = ~strcmpi(wp,pwd) | ~strcmpi(ws,s) | ...
(~isempty(ext) & ~strcmpi(wext,ext));
else
cont = ~isequal(wp,pwd) | ~isequal(ws,s) | ...
(~isempty(ext) & ~isequal(wext,ext));
end
if cont
if exist([s ext],'file')
cd(cur)
rehash;
error('MATLAB:run:CannotExecute','Can''t run %s.',[s ext]);
else
cd(cur)
rehash;
error('MATLAB:run:FileNotFound','Can''t find %s.',[s ext]);
end
end
try
feval(s,varargin{:});
% evalin('caller', [s ';']);
catch e
cd(cur);
rethrow(e);
end
else
cd(cur)
rehash;
error('MATLAB:run:FileNotFound','%s not found.',script)
end
cd(cur)
rehash;
else
error('MATLAB:run:FileNotFound','%s not found.',script)
end
else
if exist(script,'file')
evalin('caller',[script ';']);
else
error('MATLAB:run:FileNotFound','%s not found.',script)
end
end
end
libpath = '/home/user/mylib';
% move mylib to the end of the path
addpath(libpath, '-end');
% now call some built-in functions that mylib overwrites
reshape(rand(100),10,10);
% return mylib to the top
addpath(libpath)