switch.txt >> help switch SWITCH Switch among several cases based on expression. The general form of the SWITCH statement is: SWITCH switch_expr CASE case_expr, statement, ..., statement CASE {case_expr1, case_expr2, case_expr3,...} statement, ..., statement ... OTHERWISE, statement, ..., statement END The first CASE where the switch_expr matches the case_expr is executed. When the case expression is a cell array (as in the second case above), the case_expr matches if any of the elements of the cell array match the switch expression. If none of the case expressions match the switch expression then the OTHERWISE case is executed (if it exists). Only one CASE is executed and execution resumes with the statement after the END. The switch_expr can be a scalar or a string. A scalar switch_expr matches a case_expr if switch_expr==case_expr. A string switch_expr matches a case_expr if strcmp(switch_expr,case_expr) returns 1 (true). Example (assuming METHOD exists as a string variable): switch lower(METHOD) case {'linear','bilinear'}, disp('Method is linear') case 'cubic', disp('Method is cubic') case 'nearest', disp('Method is nearest') otherwise, disp('Unknown method.') end See also CASE, OTHERWISE, IF, WHILE, FOR, END. >> >> help case CASE SWITCH statement case. CASE is part of the SWITCH statement syntax, whose general form is: SWITCH switch_expr CASE case_expr, statement, ..., statement CASE {case_expr1, case_expr2, case_expr3,...} statement, ..., statement ... OTHERWISE, statement, ..., statement END See SWITCH for more details. >> >> help otherwise OTHERWISE Default SWITCH statement case. OTHERWISE is part of the SWITCH statement syntax, whose general form is: SWITCH switch_expr CASE case_expr, statement, ..., statement CASE {case_expr1, case_expr2, case_expr3,...} statement, ..., statement ... OTHERWISE, statement, ..., statement END The OTHERWISE part is executed only if none of the preceeding case expressions match the switch expression. See SWITCH for more details. >> diary off