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

3 vues (au cours des 30 derniers jours)
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

Réponse acceptée

Star Strider
Star Strider le 25 Fév 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 commentaires
Becky CNS
Becky CNS le 26 Fév 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
Star Strider
Star Strider le 26 Fév 2018
The documentation on Base and Function Workspaces (link) will help explain the relationship between them.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Cell Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by