MATLAB POLYSPACE RELEASE NOTES Manual de usuario Pagina 156

  • Descarga
  • Añadir a mis manuales
  • Imprimir
  • Pagina
    / 240
  • Tabla de contenidos
  • MARCADORES
  • Valorado. / 5. Basado en revisión del cliente
Vista de pagina 155
4 Programming
Similarly, you can create a cell array from the name fields by enclosing the
list-generating expression within curly braces:
names = {S.name}
names =
'Ed Plum' 'Toni Miller' 'Jerry Garcia'
To assign the fields of each element of a structure array to separate variables
outside o f the structure, specify each output to the left of the equals sign,
enclosing them all within square brackets:
[N1 N2 N3] = S.name
N1 =
Ed Plum
N2 =
Toni Miller
N3 =
Jerry Garcia
Dynamic Field Names
The most common way to access the data in a structure is by specifying the
name of the field that you want to reference. A nother means of accessing
structure data is to use dynamic field names. These names express the
field as a variable expression that MATLAB evaluates at run-time. The
dot-parentheses syntax shown here makes
expression adynamicfieldname:
structName.(expression)
Index into this field using the standard MATLAB indexing syntax. For
example, to evaluate
expression into a field name and obtain the values of
that field at columns
1 through 25 of row 7,use
structName.(expression)(7,1:25)
Dynamic Field Nam es Exam pl e. The avgscore function shown b elow
computes an average test score, retrieving information from the
testscores
structure using dynamic field names:
function avg = avgscore(testscores, student, first, last)
for k = first: last
scores(k) = testscores.(student).w eek( k);
4-18
Vista de pagina 155
1 2 ... 151 152 153 154 155 156 157 158 159 160 161 ... 239 240

Comentarios a estos manuales

Sin comentarios