signal statues Name function
显示 更早的评论
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
2019-3-3
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 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!