File: ef230-2023-08/www/examples/switcher.m Download
%! Example of using a switch statement with a menu
% University of Tennessee : EF 230 Fall, 2009 : Jared Graves

clear all; close all; clc;

options = {'Circle','Square','Triangle'};
ch = menu('Pick a shape',options);
switch ch
    case 1 % circle
        t=linspace(0,2*pi,100);
        x=cos(t);
        y=sin(t);
    case 2 % square
        x=[0 0 1 1];
        y=[0 1 1 0];
    case 3 % triangle
        x=[0 1 .5];
        y=[0 0 1];
    otherwise
        error('No choice made');
end
axis equal
axis off;
patch(x,y,'r');
title(options{ch});