Field values from structure array


a = extractfield(s, name)


a = extractfield(s, name) returns the field values specified by the field named name into the 1-by-n output array a. n is the total number of elements in the field name of structure s, that is, n = numel([s(:).(name)]). name is a case-sensitive string defining the field name of the structure s. a is a cell array if any field values in the field name contain a string or if the field values are not uniform in type; otherwise a is the same type as the field values. The shape of the input field is not preserved in a.


% Plot the X, Y coordinates of the road's shape
roads = shaperead('concord_roads.shp');

% Extract the names of the roads
roads = shaperead('concord_roads.shp');
names = extractfield(roads,'STREETNAME');

% Extract a mix-type field into a cell array
S(1).Type = 0;
S(2).Type = logical(0);
mixedType = extractfield(S,'Type');

See Also


Was this topic helpful?