Extracting portions of data using indices

조회 수: 2 (최근 30일)
alexandra ligeti
alexandra ligeti 2023년 11월 21일
댓글: Mathieu NOE 2023년 11월 24일
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.

채택된 답변

Mathieu NOE
Mathieu NOE 2023년 11월 21일
편집: Mathieu NOE 2023년 11월 21일
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 :
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
% store structure T in one cell Gait_cycles
Gait_cycles{1} = T;
  댓글 수: 8
alexandra ligeti
alexandra ligeti 2023년 11월 23일
Ah cheers, thanks for that. Had a few errors but have got it all working now.
Mathieu NOE
Mathieu NOE 2023년 11월 24일
my pleasure !

댓글을 달려면 로그인하십시오.

추가 답변 (0개)


Help CenterFile Exchange에서 General Applications에 대해 자세히 알아보기


Community Treasure Hunt

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

Start Hunting!

Translated by