Extracting portions of data using indices

4 visualizzazioni (ultimi 30 giorni)
Hello,
I have a 1x1 cell titled trim_data as attached below, which contains a variety of gait data. I then also have a list of indexes where heel strike occurs.
I would like to section all the data in trim_data into a new cell titled Gait cycles that contains each portion of data from heel strike to the next heel strike in different structures. If there are 10 indices there should be 9 gait cycles and therefore 9 structures contatining data. I would like the structures to be divided up from the first index value to the second index value and that would be gait cycle 1 and then divided from the second index value to the third index value to make gait cycle 2 and then another structure from index three to index four to make gait cycle 3 etc etc for as many indexes there are.
I have tried using cellfun but I am getting nowhere with it. How would you do this, or where would one even start trying to do this?
I have attached the data below.
If this question is unclear please reach out.

Risposta accettata

Mathieu NOE
Mathieu NOE il 21 Nov 2023
Modificato: Mathieu NOE il 21 Nov 2023
hello Alexandra and welcome back !
I tried this , let me know if it's what you needed
the output cell (Gait_cycles) contain now 9 structures with same fields as in the original data , splitted accordingly to your indexes
code :
load('H05_T05_HS_INDEX.mat')
load('trim_data.mat')
S = trim{1}; % extract struct from cell
FN = fieldnames(S); % get field names from S
for ci = 1:numel(idx_HS)-1
T(ci).count = ci; % just to create a new structure T with new field "count" = block data index (for fun)
start_index = idx_HS(ci);
stop_index = idx_HS(ci+1);
for ck = 1:numel(FN)
fn = FN{ck};
% get data related to that fieldname
data = S.(fn);
T(ci).(fn) = data((start_index:stop_index),:); % store data within start / stop indexes
end
end
% store structure T in one cell Gait_cycles
Gait_cycles{1} = T;
  8 Commenti
alexandra ligeti
alexandra ligeti il 23 Nov 2023
Ah cheers, thanks for that. Had a few errors but have got it all working now.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Structures in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by