I have two functions, one is called from inside of another. I want certain parts of the first function to not execute when being called within the second function.
function vvec = vecVelocity(varargin);
%must be preceded with a 'syms var real' declaration where var is
%the parameter of your vector function
if nargin > 1 & nargin < 3
r = [sym(varargin(1:end))];
elseif nargin > 3
disp('too many inputs')
return
else r = [sym(varargin(1))];
end
if length(r) < 3
r = [r,0];
end
dr = diff(r);
uT = vecUnitTan(r);
speed = sqrt(sum(dr.^2));
v = speed*uT;
vvec = matlabFunction(v);
disp(['Simplified Symbolic Form: ' char(simplify(sym(vvec)))]);
I would like to suppress this last line disp(...) from appearing when I call this following second function from the command window
function speed = vecSpeed(r);
%must be preceded with a 'syms var real' declaration where var is
%the parameter of your vector function
v = sym(vecVelocity(r));
sp = sqrt(sum(v.^2));
speed = matlabFunction(sp);
disp(['Simplified Symbolic Form: ' char(simplify(sym(speed)))]);
At the moment, calling the vecSpeed function, causes a bunch of statements to be displayed from other preceding functions that are called from within the vecSpeed function (and some that are called from within the vecVelocity function), but I only want the disp(...) statement from the vecSpeed function to be called, not any of the others.
In the first function, you can put a block of codes in
if numel(dbstack) == 1
% Your code block
end
to prevent them to be executed unless the function is being called directly from Command Window.
Another way is to check for existence of some variables like debug_1
, debug_2
etc.. which you can pass from the 2nd function when you call the 1st function.