Download script and run it
14 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I would like to have the following functionality:
websave('dummy.m', 'https://something.com/../coolscript.m');
disp(dummy(rand))
delete('dummy.m');
but without the temporary file.
Is it possible?
2 comentarios
Rik
el 2 de Nov. de 2017
I don't think it is, unless you are going to use eval, and even then it depends on the script (as not all functions can be eval-ed). Why do you have a problem with the temporary file?
PS DON'T USE EVAL. Stephen Cobeldick is very pasionate about this topic (and with good reason), so I have taken the liberty of adapting some of his thoughts on this topic: Introspective programing (eval and other functions like it) is slow, and the MATLAB documentation warns specifically against it. Using eval is slow, makes debugging difficult, and removes all code helper tools (code checking, syntax hints, code completion, variable highlighting, etc.). A longer discussion can be found here. If you are not an expert and you think you need eval, there are probably better solutions to your problem.
Respuestas (1)
Walter Roberson
el 3 de Nov. de 2017
run is a script that you can look at. It finds the file name, cd's to the directory, runs the function, cd's back.
You can create a wrapper function to do the execution:
function varargout = runfunc(url, varargin)
if ~exist('url', 'var') || ~(ischar(url) || isstring(url)) || isempty(url)
error('bad url');
end
olddir = pwd;
cleanMe = onCleanup(@() cd(olddir) );
tfile = [tempname '.m'];
try
websave(tfile, url);
cleanMe2 = onCleanup(@() delete(tfile));
catch ME
rethrow(ME);
end
[tfilepath, tfilename, ext] = fileparts(tfile);
try
cd(tfilepath);
[varargout{1:nargout}] = feval(tfilename, varargin{:});
catch ME
rethrow(ME);
end
clear cleanMe2 cleanMe
end
0 comentarios
Ver también
Categorías
Más información sobre Downloads en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!