struct
Creates one or more structs with the specified fields and values.
Syntax
R = struct(x1,y1,x2,y2,.....)
Inputs
- x1
- Field name for the resultant struct.
- y1
- Values of x1. If the value in not a single element, then it must be a cell that contains the individual values. All value elements (y1, y2, ...) must have the same dimension.
Outputs
- R
- Resultant struct array.
Examples
Single struct
example:
R = struct('foo', 1)
R = struct [
foo: 1
]
Struct array
example:
R = struct('foo', {1,2,3}, 'bar', {'a','b','c'})
R = struct [
Struct array of size 1 x 3 with fields:
bar
foo
]
Comments
If you want to assign the value of a field in a struct to a cell, you have to use an extra
set of {}. Otherwise, the function makes a struct array matching the size of the cell.
a = struct('a', {1,2,3})
b = struct('a', {{1,2,3}})