To append new fieldnames with values to a structure in MATLAB, you can use the dot notation.
Suppose you have a structure named myStruct
and you want to add a new field newField
with value newValue
, you can use the following syntax:
main.m30 chars2 lines
For example, if myStruct
already has a field named field1
, you can add a new field named newField
with value 10
as follows:
main.m45 chars3 lines
You can also add multiple fieldnames and values using the same dot notation. For example, you can add two new fields newField1
and newField2
with values newValue1
and newValue2
, respectively, as follows:
main.m64 chars3 lines
Note that when you add new fields to a structure, MATLAB automatically expands the structure to accommodate the new fields.
gistlibby LogSnag