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)
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]

Answers (1)

TED MOSBY
TED MOSBY on 9 Jul 2025
Edited: TED MOSBY on 9 Jul 2025
Hi,
I can provide a high level workflow for this:
  1. Mark every frame where the foot is on the ground (stance mask).
  2. Detect heel-strikes by finding where that mask first turns on.
  3. Chop the trial between heel-strikes → each chunk = one gait cycle.
  4. Store those chunks in a cell array so you can run per-cycle statistics.
  5. Print and plot so you can see the slicing.
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!

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!