MatLab Question Rewrite the following nested ifelse statemen
MatLab Question
Re-write the following nested if–else statement as a switch statement that accomplishes exactly the same result for all possible values. Assume that val is an integer variable that has been initialized, and that “ok”, “xx”, “yy”, “tt”, and “mid” are functions. Writethe switch statement in the most succinct way.
if val 5 if val ok (va1) elseif val 9 xx (val) else yy (val) end el se ifval 3 yy (val) elseif val = 3 tt (val) else mid(val) end endSolution
switch(val)
case{6,7}
ok(val);
case{8,9}
xx(val);
case 3
tt(val);
case{4,5}
mid(val);
otherwise
disp(\"Invalid number\");
end
