# Inserting more rows between already existing rows of a structure

6 views (last 30 days)
Katy Weihrich on 21 May 2019
Edited: Stephen23 on 21 May 2019
Hello,
I am trying to extract data of interest from a time data series in the form of episodes.
Y = accelerometer data
t = time data
pks & locs = location and amplitude of peaks of interest
I already have sections of data which could be data of interest into episodes in the structure:
n = amount of episodes
grp_pks(n).Y = Y(1,i_str:i_end);
grp_pks(n).t = t(1,i_str:i_end);
grp_pks(n).i = [i_str, i_end];
grp_pks(n).pks = pks;
grp_pks(n).locs = locs;
After analysing the peaks further, I want to devide the episodes when peaks are further apart then 2 sec and delete episodes with > 5 peaks.
Therefore, I would need to be able to insert extra n into the structure, e.g. having grp_pks(3) devided into grp_pks(3), grp_pks(4), grp_pks(5), ... without overwriting the grp_pks(4), grp_pks(5), ... . Is that possible? with Matrixes I would just do:
mtx_pks = [mtx_pks(1:2,:); pks; mtx_pks(4:end,:)];
but I am not sure how to tansfere that onto a structure.
Thank you

Stephen23 on 21 May 2019
Edited: Stephen23 on 21 May 2019
"but I am not sure how to tansfere that onto a structure. "
In exactly the same way. All MATLAB arrays use the same indexing concept, so if you can do it with a numeric array then you can do it with a structure array. You can concatenate, use indexing to select subsets, or to assign to specific values, reshape, etc., just as with every other type of array.
Important to keep in mind is that when using indexing into a structure the structure being allocated must have exactly the same fields.

### Categories

Find more on Structures in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!