- 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.
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
TED MOSBY
2025-7-9
编辑:TED MOSBY
2025-7-9
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!