Is there a way how to run MATLAB script from specific line without using GUI.
In GUI I use %%
.
Thanks
Is there a way how to run MATLAB script from specific line without using GUI.
In GUI I use %%
.
Thanks
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.
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.
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,'%[^\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