Programming |
Applying Functions and Operators
Operate on fields and field elements the same way you operate on any other MATLAB array. Use indexing to access the data on which to operate. For example, this statement finds the mean across the rows of the test
array in patient(2)
:
There are sometimes multiple ways to apply functions or operators across fields in a structure array. One way to add all the billing
fields in the patient
array is
To simplify operations like this, MATLAB enables you to operate on all like-named fields in a structure array. Simply enclose the array.field
expression in square brackets within the function call. For example, you can sum all the billing
fields in the patient
array using
This is equivalent to using the comma-separated list:
This syntax is most useful in cases where the operand field is a scalar field:
Finding the Size of Structure Arrays | Writing Functions to Operate on Structures |
© 1994-2005 The MathWorks, Inc.