필터 지우기
필터 지우기

output arguments not assigned

조회 수: 5 (최근 30일)
Sarah K
Sarah K 2019년 10월 22일
댓글: David Hill 2019년 10월 22일
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.

답변 (1개)

David Hill
David Hill 2019년 10월 22일
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
Sarah K
Sarah K 2019년 10월 22일
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 2019년 10월 22일
No, the output is generally a different named variable.
function [outcome] = name_of_function(input)
outcome=2*input;
end

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Variables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by