extractfield
Field values from structure array
Syntax
Description
Examples
Load a structure that contains information about roads in Concord, MA.
roads = shaperead('concord_roads.shp');
r = roads(1:5);
Get the x- and y-coordinates of the roads. Display the map, and highlight the first few elements using the color magenta.
hold on plot(extractfield(roads,'X'),extractfield(roads,'Y')); plot(extractfield(r,'X'),extractfield(r,'Y'),'m');
Extract the names of the roads, stored in the field STREETNAME
. The field values are character vectors, so the result is returned in a cell array.
names = extractfield(r,'STREETNAME');
Extract the X
field from the structure and examine the format of the returned values. All values have the same numeric data type (double
), so the result is returned in a vector.
uniformType = extractfield(r,'X');
For illustrative purposes, change the X field value in one of the elements to have a different data type. This command converts the second element to data type single
.
r(2).X = single(r(2).X);
Extract the X
field values again. This time, the values have different data types, so the result is returned in a cell array.
mixedType = extractfield(r,'X');
Input Arguments
Structure, specified as a structure.
Field name, specified as a case-sensitive string scalar or character vector.
Output Arguments
Extracted field values, returned as a 1-by-n numeric
vector or cell array. n is the total number of elements
in the field name
of structure S
,
that is, n = numel([S(:).(name)])
. a
is a cell array if any field values in the field name contain a character
vector 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
.
Version History
Introduced before R2006a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)