File Exchange

image thumbnail

Subscripted Reference for Structures

version 1.2.0.0 (3.7 KB) by Brian Emery
Applies indexing to the fields of a structure.

0 Downloads

Updated 09 May 2011

View Version History

View License

Applies indexing to the fields in a structure in much the same way as subsref.m works with matricies, vectors, etc. The indexing is only applied to fields with n columns (or rows).

Example call: S = subsref_struct(S,i,n,rc)

Applies the indexing given in i, to the fields in S that have the
matching number of columns (n). Given a 4th input will apply the indexing to the rows (1) or columns (2), defaults to columns.

Example:
Create a structure with mixed fields, array and structure
d.lon = ones(5,1)*[1:10];
d.lat = ones(5,1)*[1:10];
d.time = 1:10;
d.strct = d;

Change the column indexing
S = subsref_struct(d,2:5,size(d.lon,2),2)

Change the row indexing
S = subsref_struct(d,1:2,size(d.lon,1),1)

Cite As

Brian Emery (2021). Subscripted Reference for Structures (https://www.mathworks.com/matlabcentral/fileexchange/29003-subscripted-reference-for-structures), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (2)

Brian Emery

Thanks for pointing that out! The example works now.

Matthew

The example doesn't work....

MATLAB Release Compatibility
Created with R2007b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!

subsref_struct/