How can I suppress the output of another function that is called from my function?

조회 수: 4 (최근 30일)
I am trying to compile the roots calculated from a bisection method function and an incremental search method function. The output of nb from the incremental search function continually appears even when I suppress the incremental search function.
%my original function
function [X] = manyRoots(func,a,b,ns,tol)
%manyRoots: root location zeroes
%combines bisect and incsearch to detect roots when sign change occurs
%input:
%func = name of function
%xl = lower bound of the bracket
%xu = upper bound of the bracket
%ns = number of sub intervals
%tol = the desired tolerance
%output:
%roots = real roots
y = bisect(func,a,b,tol);
z = incsearch(func,a,b,ns);
[X]=[y,z];
end
I am trying to supress the nb from this function.
function xb = incsearch(func,xmin,xmax,ns)
% incsearch: incremental search root locator
% xb = incsearch(func,xmin,xmax,ns):
% finds brackets of x that contain sign changes
% of a function on an interval
% input:
% func = name of function
% xmin, xmax = endpoints of interval
% ns = number of subintervals (default = 50)
% output:
% xb(k,1) is the lower bound of the kth sign change
% xb(k,2) is the upper bound of the kth sign change
% If no brackets found, xb = [].
if nargin < 3, error('at least 3 arguments required'), end
if nargin < 4, ns = 50; end %if ns blank set to 50
% Incremental search
x = linspace(xmin,xmax,ns);
f = func(x);
nb = 0; xb = []; %xb is null unless sign change detected
for k = 1:length(x)-1
if sign(f(k)) ~= sign(f(k+1)) %check for sign change
nb = nb + 1;
xb(nb,1) = x(k);
xb(nb,2) = x(k+1);
end
end
if isempty(xb) %display that no brackets were found
disp('no brackets found')
disp('check interval or increase ns')
else
disp('number of brackets:') %display number of brackets
disp(nb)
end
I am trying to suppress the number of brackets that shows up above my answer X.

채택된 답변

Sean de Wolski
Sean de Wolski 2020년 9월 17일
Easiest way would be to pass an optional flag into incsearch that specifies whether it should display or not.
function xb = incsearch(func,xmin,xmax,ns, verbose)
% incsearch: incremental search root locator
% xb = incsearch(func,xmin,xmax,ns):
% finds brackets of x that contain sign changes
% of a function on an interval
% input:
% func = name of function
% xmin, xmax = endpoints of interval
% ns = number of subintervals (default = 50)
% output:
% xb(k,1) is the lower bound of the kth sign change
% xb(k,2) is the upper bound of the kth sign change
% If no brackets found, xb = [].
arguments
func
xmin
xmax
ns = 50
verbose = true
end
if verbose
disp stuff
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Particle & Nuclear Physics에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by