![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1545752/image.png)
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1545752/image.png)
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 中查找有关 Data Type Conversion 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!