Note: This page has been translated by MathWorks. Click here to see

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Assign value to structure array field

`S = setfield(S,field,value)`

`S = setfield(S,field1,...,fieldN,value)`

`S = setfield(S,idx,field1,...,fieldN,value)`

`S = setfield(S,idx,field1,idx1,...,fieldN,idxN,value)`

`S = setfield(`

assigns a value to the specified field of the structure `S`

,`field`

,`value`

)`S`

. For example,
`S = setfield(S,'a',1)`

makes the assignment ```
S.a =
1
```

.

As an alternative to `setfield`

, use dot notation: ```
S.field =
value
```

. Dot notation is typically more efficient.

If `S`

does not have the specified field, then
`setfield`

creates it and assigns `value`

to
it.

`fieldnames`

| `getfield`

| `isfield`

| `orderfields`

| `rmfield`

| `struct`