一些选择:
添加一个参数以指定控制台的详细输出,但默认情况下将其设置为false:
function [ A, B, C ] = test(x, y, z, verbose)
if nargin = 3
verbose = false;
end;
A=2*x;
B=2*y;
C=2*z;
if verbose
fprintf('A = %f\nB = %f\nC = %f', A, B, C);
end;
end
或将它们组合成一个输出:
function output = test(x, y, z)
A=2*x;
B=2*y;
C=2*z;
output = [A, B, C]; %// Or {A;B;C} if they're not going to be the same size, but then it won't display anyway
end
或者如果你真的想要我猜你可以编写一个你在函数上调用的包装器函数,它会显示你可以在任何函数上使用的所有三个函数.但这似乎不值得.