structindex

Two mex files: structindex selects elements from all fields of a structure ....
968 Downloads
Updated 20 Apr 2005

No License

This is for those people who like structures of arrays (rather than arrays of structures). They tend to be faster, and require less memory.

There are two functions in this package. "structindex" selects elements from all fields of a structure, while "structcat" concatinates two (or more) like structures.

I've included the MEX files for Windows (Matlab ver 6.5?). To compile it for your platform, try
mex structindex.c
and
mex structcat.c

STRUCTINDEX Extract data elements from a structure of arrays.
STRUCTINDEX(S,INDEX) returns selected data elements from each field of S. The returned value has all the same fields as S, and each field will have as many elements as are in INDEX. INDEX is an array of indecies to select. If a given index does not exist for a particular field of S, a default value for the data element is used.

Currently, indexing in one-dimensional only (fields having data of two or more dimensions are not supported). Also, indexing through the use use of logical arrays is not supported at this time.

EXAMPLES:
s.name = {'sam','mike','john'};
s.income = [10000,90000,-10];
structindex(s,2:3)
ans =
name: {'mike' 'john'}
income: [90000 -10]
structindex(s,[2 2 2 99])
Warning: Index vector contained values exceeding structure field sizes
ans =
name: {'mike' 'mike' 'mike' []}
income: [90000 90000 90000 0]

See also STRUCTCAT.%STRUCTCAT Concatination of fields of two or more structures.

STRUCTCAT(S1,S2,...) returns selected data elements from each field. The returned structure will have all fields that are contained in the input structures. Each field will be the (one-dimensional) concatination of all data from the input structures containging that field.

EXAMPLES:
s.name = {'sam','mike','john'};
s.income = [10000,90000,-10];
g.name = {'julie','carol'};
g.income = [15000,120000];
g.age = [19 64];
structcat(s,g)
ans =
name: {'sam' 'mike' 'john' 'julie' 'carol'}
income: [10000 90000 -10 15000 120000]
age: [19 64]

See also STRUCTINDEX.

Cite As

AJ Johnson (2024). structindex (https://www.mathworks.com/matlabcentral/fileexchange/7469-structindex), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R13
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Structures in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.0.0