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

3 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Star Strider
Star Strider am 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 Kommentare
Becky CNS
Becky CNS am 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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Cell Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by