## Structure Cut

Version 1.0.0.0 (1.56 KB) by
Utility function that applies the same cut to specified elements of a structure.

Updated 18 Oct 2010

As an example, suppose you had taken 155 seconds of data of the location (x,y,z) of a particle as a function of time (t). It is convenient to put that all into a struct, such as this one:

>> data

data =

t: [155000x1 double]
x: [155000x1 double]
y: [155000x1 double]
z: [155000x1 double]

If you wanted to extract the data taken between 15 and 20 seconds, you would normally need to type

index = find((data.t > 15) & (data.t < 20));
cut_data.t = data.t(index);
cut_data.x = data.x(index);
cut_data.y = data.y(index);
cut_data.z = data.z(index);

Tedious, and prone to typos! Using the function "struct_cut" you can do the same thing by just typing

index = find((data.t > 15) & (data.t < 20));
cut_data = struct_cut(data,{'t','x','y','z'},index);

If you want to apply different cuts to each element of the structure, just type

cut_data = struct_cut(data,{'t','x','y','z'},{i_t,i_x,i_y,i_z});

where "i_t", "i_x", etc are four different cut arrays you make elsewhere.

I tested this with ~10-100 megabyte data sets, and it runs really fast. Hopefully it will work well for larger arrays also, please let me know!

### Cite As

Sean Bryan (2023). Structure Cut (https://www.mathworks.com/matlabcentral/fileexchange/29074-structure-cut), MATLAB Central File Exchange. Retrieved .

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