- Create 5-by-5 array of magic square numbers
- Create a 5-by-5 object array
F = magic(5);
A = ObjectArray(F);
whos
Name Size Bytes Class Attributes
A 5x5 304 ObjectArray
F 5x5 200 double
Referencing Property Values in Object Arrays
Given an object array objArray in which each object has a property PropName:
- Reference the property values of specific objects using array indexing:
objArray(ix).PropName
- Reference all values of the same property in an object array using dot notation.
MATLAB returns a comma-separated list of property values.
objArray.PropName
- To assign the comma-separated list to a variable, enclose the right-side expression in
brackets:
values = [objArray.PropName]
For example, given the ObjProp class:
classdef ObjProp
properties
RegProp
end
methods
function obj = ObjProp
obj.RegProp = randi(100);
end
end
end
Create an array of ObjProp objects: