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