MATLAB Answers

why do I have unrecognized function error for z?

1 view (last 30 days)
John Martinez
John Martinez on 20 Nov 2020
Edited: VBBV on 20 Nov 2020
I thought I defined z by putting it in the switch.

  1 Comment

KSSV
KSSV on 20 Nov 2020
Don't attach your code as a image snippet. You can always copy paste your code here.
What is variable buff?

Sign in to comment.

Answers (2)

Steven Lord
Steven Lord on 20 Nov 2020
What should the value of z be if buff is none of "none", "30min", or "60min"? What if buff was "30 minutes", for example?

  0 Comments

Sign in to comment.


VBBV
VBBV on 20 Nov 2020
Edited: VBBV on 20 Nov 2020
%if true
buff = char(buff);% convert to char or number
switch buff
case 'none'
z = 0;
case '30min'
z = 12;
case '60min'
z = 24;
end
If the input value contains only numeric, then conversion to char is not necessary. e.g. case 0, case 30 case 60. Otherwise it's needed in switch as shown abov In your program, the switch case is not being executed and directly jumps to next line after end.

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!