Function of multiple outputs produces only one answer or three with a redundant 'ans' . How to fix?

3 views (last 30 days)
I only want the two output outlined in the function with the corresponding titles
but this produces only one answer 'ans':
function [ampres,amplevels] = ADconverterAmps(bits,rangeVolts)
ampres = (rangeVolts)/(2^(bits));
amplevels = [2^(bits)];
end
While this produces three including a redundant value for ans which is the first output anyway
function [ampres,amplevels] = ADconverterAmps(bits,rangeVolts)
ampres = (rangeVolts)/(2^(bits))
amplevels = [2^(bits)]
end

Accepted Answer

Star Strider
Star Strider on 25 Feb 2018
Use a semicolon (;) at the end of each line to suppress the output to your Command Window:
function [ampres,amplevels] = ADconverterAmps(bits,rangeVolts)
ampres = (rangeVolts)/(2^(bits));
amplevels = [2^(bits)];
end
When you call the functions, put a semicolon at the end of the function call line to suppress the function output displaying to the Command Window:
[ampres,amplevels] = ADconverterAmps(bits,rangeVolts);
That should work.
See the documentation on Special Characters [ ] ( ) {} = ' . ... , ; : % ! @ (link) for details on it and others.
  5 Comments
Becky CNS
Becky CNS on 26 Feb 2018
Ah I didn't realise you have to specify the output variables when writing the command to store in the workspace.
So yes, no semi-colons within the function script but then a semi-colon following the command did the job

Sign in to comment.

More Answers (0)

Categories

Find more on Cell Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!