是否有一种优雅的方式告诉matlab在执行某个脚本中的每一行后执行预定义的操作?优雅我的意思是在每一行之后都没有调用动作,而是在脚本开头给出一个简单的命令.
示例:操作 - > disp('Performing Action');
脚本:
a = 1;
b = 2;
c = 3;
Run Code Online (Sandbox Code Playgroud)
因此,期望的结果是在每次分配(a,b和c)之后,将执行disp()命令.
您可以自动创建一个修改过的文件,其中包含每行末尾所需的操作:
action = 'disp(''Performing Action'');'; %// action to be added at the end of each line
file = 'script.m'; %// original script
file_out = 'script_out.m'; %// modified script with action added
x = importdata(file); %// cell array of strings. Each line of the
%// original file is a string
x = strcat(x, {' ; '}, action); %// add action at the end of each string,
%// preceded with `;` in case the original line
%// didn't include that
fid = fopen(file_out, 'w');
fprintf(fid, '%s\n', x{:}); %// write output file
fclose(fid);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
114 次 |
| 最近记录: |