Take an example,
a = struct('in',1,'out',2)
b = struct('temperature',6,'light',5,'output',2)
How do I get the last field and value that I input?
Take an example,
a = struct('in',1,'out',2)
b = struct('temperature',6,'light',5,'output',2)
How do I get the last field and value that I input?
To get the last field of a
,
z = a.out
To get the last field of b
,
x = b.output
Or if you don't know what the field names are you can find them in the following way:
names = fieldnames(a)
I hope that helps.
The documentation for a struct says:
The most common way to access the data in a structure is by specifying the name of the field that you want to reference.
In contrast to an array, where elements are accessed by index -> position, a struct field is accessed by the fieldname -> name.
See How do I access MATLAB structure fields within a loop? on how to iterate over all all fields of a struct.