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]

回答(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