Borrar filtros
Borrar filtros

output arguments not assigned

5 visualizaciones (últimos 30 días)
Sarah K
Sarah K el 22 de Oct. de 2019
Comentada: David Hill el 22 de Oct. de 2019
Hello,
When I run this function
function [outcome] = days_of_the_week(day)
end
Output argument "outcome" (and maybe others) not assigned
Matlab says outcome argument not assigned (but still works despite this error)
BUT when I change [outcome] to [day]
function [day] = days_of_the_week(day)
end
The error goes away and the function works
Why?
Am I missing something obvious? Apologies, I am new to Matlab. Thank you.

Respuestas (1)

David Hill
David Hill el 22 de Oct. de 2019
Because 'day' is the input variable, it is present in the function and will be passed to the output. the 'outcome' variable is never assigned in the function, so the error tells you that and nothing gets passed to the output. The error does not cause the function, which does nothing, not to work.
  4 comentarios
Sarah K
Sarah K el 22 de Oct. de 2019
so the name assigned to the [outcome] should always be the same as the name assigned to the (input), for basic purposes? Thanks.
function [outcome] = name_of_function(input)
end
David Hill
David Hill el 22 de Oct. de 2019
No, the output is generally a different named variable.
function [outcome] = name_of_function(input)
outcome=2*input;
end

Iniciar sesión para comentar.

Categorías

Más información sobre Variables en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by