setfield
Sets the value of field f in the stucture s to the value v.
Syntax
R = setfield(s,f,v)
R = setfield(s,f,v,idx)
Inputs
- s
- Struct.
- f
- Field.
- v
- Value to set.
- idx
- The index (or indices) of the element in the struct array to modify. Must be stored in a cell array.
Outputs
- R
- Resulting structure.
Examples
a = struct('name', 'Bob', 'age', 33);
R = setfield(a, 'age', 34)
R = struct [
age: 34
name: Bob
]
a = struct('name', {'Bob', 'Dave'}, 'age', {33, 44});
R = setfield(a, {1}, 'age', 34)
R(1)
R = struct [
Struct array of size 1 x 2 with fields:
age
name
]
ans = struct [
age: 34
name: Bob
]