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 (최근 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]

답변 (1개)

TED MOSBY
TED MOSBY 2025년 7월 9일
편집: TED MOSBY 2025년 7월 9일
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!

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by