Extracting portions of data using indices
조회 수: 6 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
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 :
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!