MATLAB POLYSPACE RELEASE NOTES Manuel d'utilisateur Page 142

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 240
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 141
4 Programming
elseif A < B
'less'
elseif A == B
'equal'
else
error('Unexpected situatio n')
end
Several functions are helpful for reducing the results of matrix comparisons
to scalar cond itions for use with
if, including
isequal
isempty
all
any
switch and case
The switch statement executes groups of statements based on the value of
a variable or expression. The keywords
case and otherwise delineate the
groups. Only the first m atching case is executed. There must always be an
end to ma tch the switch.
The logic of the magic squares algorithm can also be described by
switch (rem(n,4)==0) + (rem(n,2)==0)
case 0
M = odd_magic(n)
case 1
M = single_even_magic( n)
case 2
M = double_even_magic( n)
otherwise
error('This is impossible')
end
Note Unlike the C language switch statement, MATLAB sw itch does not
fall through. If the first
case statem ent is true, the other case statements do
not e xecute. So,
break statements are n ot require d.
4-4
Vue de la page 141
1 2 ... 137 138 139 140 141 142 143 144 145 146 147 ... 239 240

Commentaires sur ces manuels

Pas de commentaire