structindex

版本 1.0.0.0 (62.0 KB) 作者: AJ Johnson
Two mex files: structindex selects elements from all fields of a structure ....
969.0 次下载
更新时间 2005/4/20

无许可证

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.

引用格式

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

MATLAB 版本兼容性
创建方式 R13
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Structures 的更多信息

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.0.0.0