How can I suppress the 'ans' output?
Show older comments
When my code looks like this
function [ z ] = summie( x,y )
z=x+y;
disp(['The summie is: ', num2str(z)])
end
and I typ in the command window for example
summie(1,2)
This is displayed:
The summie is: 3
ans =
3
Is there a way to suppress the 'ans' output, so that only
The summie is: 3
is displayed?
Accepted Answer
More Answers (1)
Matt J
on 18 Apr 2013
Add a semicolon to the end of the function call
sum(1,2);
4 Comments
Matt J
on 18 Apr 2013
Incidentally, it is a bad idea to call your function "sum", since this will conflict with MATLAB's native SUM command.
Matt J
on 19 Apr 2013
function varargout = summie( x,y )
z=x+y;
disp(['The summie is: ', num2str(z)])
if nargout
varargout{1}=z;
end
end
Jeroen
on 19 Apr 2013
Categories
Find more on Scope Variables and Generate Names in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!