next up previous contents
Next: User defined function Up: Operations Previous: Linear Regression   Contents

Switch

\includegraphics[height=10mm]{images/switchKey}% WIDTH=62 HEIGHT=46

The operator can be placed on the canvas by clicking on its icon \resizebox{!}{2ex}{\includegraphics{images/switch}}% WIDTH=29 HEIGHT=13 on the widget bar.

A switch block (also known as a case block, or select in the Fortran world) is a way of selecting from a range of alternatives according to the value of the input, effectively defining a piecewise function. \resizebox{\textwidth}{!}{\includegraphics{images/switch}}% WIDTH=527 HEIGHT=246 An example switch block with 3 cases

The default switch has two cases, and can be used to implement an if/then/else construct. However, because the two cases are 0 and 1, or false and true, a two case switch statement will naturally appear ``upside down'' to how you might think of an if statement. In other words, it looks like:

$\textstyle \parbox{1\textwidth}{%
\texttt{if not }{\em condition} \texttt{then}\\
\ldots\texttt{else}\\
\ldots %
}$% WIDTH=336 HEIGHT=102

You can add or remove cases through the context menu.