Is there a way how to run MATLAB script from specific line without GUI?
Is there a way how to run MATLAB script from specific line without using GUI.
In GUI I use %%
.
Than开发者_开发问答ks
It is possible to write to a function, that will read the script m-file, skip the lines until required one and write the rest to temporary m-file, then run it. Or from line1 to line2. Sorry, don't have access to Matlab right now to implement it. May be tomorrow, unless somebody will volunteer to do it.
UPDATE
Here is the function:
function runfromto(mfile, lfrom, lto)
% Runs mfile script from line lfrom to line lto.
if nargin < 1
error('No script m-file specified.');
end
if ~strcmp(mfile(end-1:end),'.m')
mfile = [mfile '.m'];
end
if ~exist(mfile,'file')
error(['Cannot access ' mfile])
end
M = textread(mfile,'%s','delimiter','\n');
if nargin < 2
lfrom = 1;
end
if nargin < 3 || lto > numel(M)
lto = numel(M);
end
if lfrom > numel(M)
error(['Script contains only ' num2str(numel(M)) ' lines.'])
end
for k=lfrom:lto
try
evalin('base',M{k})
catch ME
error('RunFromTo:ScriptError',...
[ME.message '\n\nError in ==> ' mfile ' at ' num2str(k) '\n\t' M{k}]);
end
end
UPDATE 2 Corrected following comments from anon.
It seems the answer is 'no': see
http://blogs.mathworks.com/desktop/2008/01/07/ive-got-something-to-cell-you/
comments 27 and 28.
A quite elegant way to solve this problem is to use the goto implementation of Husam Aldahiyat:
https://de.mathworks.com/matlabcentral/fileexchange/26949-matlab-goto-statement
Simply put
goto("your line")
return
at the beginning of your matlab script.
精彩评论