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

3 次查看(过去 30 天)
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

采纳的回答

Star Strider
Star Strider 2018-2-25
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 个评论
Becky CNS
Becky CNS 2018-2-26
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Cell Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by