Borrar filtros
Borrar filtros

Two separate outputs from one input

3 visualizaciones (últimos 30 días)
Justin Lee
Justin Lee el 21 de Sept. de 2021
Respondida: Viranch Patel el 22 de Sept. de 2021
Need help trying to write a code that would take one single input and provide two separate outputs
"Write a function that takes a single number a, and returns a*2 and a+2 as two separate output arguments."

Respuestas (1)

Viranch Patel
Viranch Patel el 22 de Sept. de 2021
You can have multiple outputs from the function like this.
function [multiply,sum] = test(x)
multiply = x*2;
sum = x+2;
end
And after that you can call the function in following manner.
[multiply, sum] = test(x);

Community Treasure Hunt

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

Start Hunting!

Translated by