一个解决方案是:
clear vars
out1=evalc('sub1');
out2=evalc('sub2');
其中out1和out2是可选的,用于捕获输出。
始终使用
;
来抑制分配的显示,并在需要时显式地单独显示变量。
在这种情况下,我们可以执行以下操作:
Inside main.mlx
, we write
% Call the sub scripts without output
bDisp = false;
sub1;
sub2;
Inside sub1.mlx
and sub2.mlx
, you can structure your outputs to be more explicit
% By default (when running this script alone), display things
if ~exist( 'bDisp', 'var' )
bDisp = true;
end
syms A1 B1
% Terminate the assignment with a semi-colon to suppress output
A1 = B1;
% Explicitly display A1 here (if bDisp is enabled)
if bDisp
A1 % disp(A1) would be even more verbose, but doesn't show "A1 = "
end
sub1.mlx
/sub2.mlx
的顶部)变得更加复杂。例如,您可以使用dbstack
来确定执行代码所调用的位置(即哪个函数),但是活动脚本与堆栈有点奇怪。