Function File: extractfield (s, field)

Extract field values from struct array.

Concatenates all the values from the field member field in the structure array s. The values are all concatenated into a row vector of the same type as the values.

s(1).field = 1:3;
s(2).field = 4:9;
extractfield (s, "field")
⇒ [ 1   2   3   4   5   6   7   8   9 ]

If any of the values is a string, or if the class is not the same for all the elements, a cell array with the intact elements is returned instead.

s(1).field = 1:3;
s(2).field = uint8 (4:6);
extractfield (s, "field")
⇒ [ 1   2   3 ]
⇒ [ 4   5   6 ]
s(1).field = "text";
s(2).field = 1:3;
extractfield (s, "field")
⇒ text
⇒ [ 1   2   3 ]

See also: cell2mat, cellfun, getfield.

Package: mapping