- Mark every frame where the foot is on the ground (stance mask).
- Detect heel-strikes by finding where that mask first turns on.
- Chop the trial between heel-strikes → each chunk = one gait cycle.
- Store those chunks in a cell array so you can run per-cycle statistics.
- Print and plot so you can see the slicing.
How can I separate gait cycles based on contact colmn in data? I have a coulmn that show stance phase with 1000 and swing phase with 0.
1 view (last 30 days)
Show older comments
Contact right=[1000;1000;1000;1000;0;0;0;0 0;0;0;0;0;1000;1000;1000;1000;1000;1000;0;0;0;0;0;0;0]
0 Comments
Answers (1)
TED MOSBY
on 9 Jul 2025
Edited: TED MOSBY
on 9 Jul 2025
Hi,
I can provide a high level workflow for this:
Here is an example code for your reference:
%% Asumming you have the data ready
stance = contact == 1000; % a) logical mask
heelStrike = find(diff([false; stance]) == 1); % b) rising edges
if numel(heelStrike) < 2
error('Need ≥2 heel-strikes to define at least one gait cycle.');
end
numCycles = numel(heelStrike) - 1;
gaitCycles = cell(numCycles,1);
cycleIdx = cell(numCycles,1);
for k = 1:numCycles
idx = heelStrike(k):heelStrike(k+1)-1;
gaitCycles{k} = data(idx,:);
cycleIdx{k} = idx;
end
fprintf('Found %d gait cycles.\n', numCycles);
fprintf('Frames per cycle: %s\n', mat2str(cellfun(@numel, cycleIdx)));
%% You can now continue to plot the above!
Hope this helps!
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!