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 end

Solution

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

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

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site