I have trouble delaing with one of my homework questions, and here is the question:
When the function is called, myParamwill contain a single character. When properly called, the function must return a character array with a message based on the instructions that follow.
If myParamcontains gthen it must return a character array containin green.
If myParamcontains ythen it must return a character array containin yellow.
For all other cases, it must return a character array containin red.
I wrote my code as this:
res = getSignalStatusName(myParam)
myParam = 'k';
if myParam == 'g'
res = 'green';
elseif myParam == 'y'
res = 'yellow';
elseif myParam == 'r'
res = 'red';
end
end
But when I ran the code, it showed that
Undefined function or variable 'res'.
Does anyone can help me about this issue? Thanks.

답변 (1개)

Stephan
Stephan 2019년 3월 3일

0 개 추천

Hi,
you fogot to specify that it is a function. This is why the error occurs:
function res = getSignalStatusName(myParam)
if myParam == 'g'
res = 'green';
elseif myParam == 'y'
res = 'yellow';
elseif myParam == 'r'
res = 'red';
end
end
I recommend to check this code again and test it against the conditions of your description. Does it really do what is wanted? I leave it to you to find this out, since it is a homework.
Best regards
Stephan

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

질문:

2019년 3월 3일

답변:

2019년 3월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by