Structure Cut
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
Platform Compatibility
Windows macOS LinuxCategories
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0.0 |