
Extracting portions of data using indices
    6 views (last 30 days)
  
       Show older comments
    
    alexandra ligeti
 on 21 Nov 2023
  
    
    
    
    
    Commented: Mathieu NOE
      
 on 24 Nov 2023
            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 Comments
Accepted Answer
  Mathieu NOE
      
 on 21 Nov 2023
        
      Edited: Mathieu NOE
      
 on 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 Comments
More Answers (0)
See Also
Categories
				Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
			
	Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
