How to incorporate a push button into GUI so that data indexes from a slider are saved to an array when the push button is clicked

3 ビュー (過去 30 日間)
Hi,
I have code that plots walking kinematic data from a person that is on a treadmil. I am trying to determine when heel strike takes place and so I have plotted the lower leg using a GUI. I would now like to incorportate a push button into the code so that I can select the frames where heel strike takes place through the various gait cycles. I would like to click the marker (Heel marker) every time the person reaches heel strike and I would like the frame number to be stored in a new array so that I have a list of where heel strike took place.
My exisiting code is as follows, please help.
close all
clear all
H = ["H05"];
sH = size(H,1);
% This file uses "walking data - raw marker data.xlsx"
[filename,pathname]= uigetfile('*.mat','Select the data file');
cd(pathname);
disp('Loading data');
%all_data = xlsread(filename,'Trial 1','A2:AS7314');
load(filename);
%[r,c] = size(all_data);
%Determine which side leg the data is collected from
SensorPosition = readtable('C:\Users\lexil\Documents\PhD\Patient_Study\CRF Trial\Healthy Participants\SensorPosition.xlsx');
for j = 1:sH
for i = 1:size(SensorPosition,1)
if strcmp(cellstr(H(j)),SensorPosition{i,1}) == 1
sensorside = SensorPosition(i,2);%issue with this line of code
end
end
end
% read in anthropometrics
%A = xlsread(filename,'Anthropometrics','A1:A19');
frame = trim{1,1}.frame;
time = trim{1,1}.time;
%time = frame * 0.01;
dt = time(2,1) - time(1,1);
yn = input('Do you want to filter the data [y/n]? ','s');
if isempty(yn)
yn = 'y';
end
if strcmp(yn,'y') == 1
%Filter the data using a butterworth 4th order filter
fs = 1/dt; % sampling frequency
% Ask to choose a cutoff frequency
fc = input('Cut off frequency [8Hz]: ');
if isempty(fc)
%default to fc = 8Hz
fc = 8;
end
end
r = size(frame,1);
if strcmp(sensorside{1,1},cellstr('left'))
disp('left!');
Toe = trim{1,1}.LToe;
Heel = trim{1,1}.LHeel;
Ankle = trim{1,1}.LAnkle;
Knee = trim{1,1}.LKne;
Thigh = trim{1,1}.LThigh;
Foot = Toe - Heel;
Calf = Ankle - Knee;
UpLeg = Knee - Thigh;
elseif strcmp(sensorside{1,1},cellstr('right'))
disp('right!');
Toe = trim{1,1}.RToe;
Heel = trim{1,1}.RHeel;
Ankle = trim{1,1}.RAnkle;
Knee = trim{1,1}.RKne;
Thigh = trim{1,1}.RThigh;
Foot = Toe - Heel;
Calf = Ankle - Knee;
UpLeg = Knee - Thigh;
else
error('Help!');
end
f = figure;
ax = axes(f);
ax.Units = 'normalized';
ax.Position = [0.1 0.2 0.8 0.7];
a=1;
% subplot(2, 1, 1)
plot3(ax,Thigh(a,1),Thigh(a,2),Thigh(a,3),'o');
hold on
plot3(ax,Knee(a,1),Knee(a,2),Knee(a,3),'o');
plot3(ax,Ankle(a,1),Ankle(a,2),Ankle(a,3),'o');
plot3(ax,Toe(a,1),Toe(a,2),Toe(a,3),'o');
plot3(ax,Heel(a,1),Heel(a,2),Heel(a,3),'o');
axis equal
% subplot(2, 1, 2);
% plot3(Ankle(:,:));
%xlim([min(Ankle(:,1)) max(Ankle(:,1))]);
%ylim([-100 100]);
%ylim([min(Ankle(:,2)) max(Ankle(:,2))]);
%zlim([min(Ankle(:,3)) max(Ankle(:,3))]);
grid on
minx = [min(Toe(:,1)) min(Heel(:,1)) min(Ankle(:,1)) min(Knee(:,1)) min(Thigh(:,1))];
maxx = [max(Toe(:,1)) max(Heel(:,1)) max(Ankle(:,1)) max(Knee(:,1)) max(Thigh(:,1))];
xlim([min(minx) max(maxx)]);
miny = [min(Toe(:,2)) min(Heel(:,2)) min(Ankle(:,2)) min(Knee(:,2)) min(Thigh(:,2))];
maxy = [max(Toe(:,2)) max(Heel(:,2)) max(Ankle(:,2)) max(Knee(:,2)) max(Thigh(:,2))];
ylim([min(miny) max(maxy)]);
minz = [min(Toe(:,3)) min(Heel(:,3)) min(Ankle(:,3)) min(Knee(:,3)) min(Thigh(:,3))];
maxz = [max(Toe(:,3)) max(Heel(:,3)) max(Ankle(:,3)) max(Knee(:,3)) max(Thigh(:,3))];
zlim([min(minz) max(maxz)]);
Hip = Thigh; % comment out when fixed
line([Hip(a,1) Knee(a,1)],[Hip(a,2) Knee(a,2)],[Hip(a,3) Knee(a,3)],'Color','k');
line([Knee(a,1) Ankle(a,1)],[Knee(a,2) Ankle(a,2)],[Knee(a,3) Ankle(a,3)],'Color','k');
line([Ankle(a,1) Toe(a,1)],[Ankle(a,2) Toe(a,2)],[Ankle(a,3) Toe(a,3)],'Color','k');
line([Ankle(a,1) Heel(a,1)],[Ankle(a,2) Heel(a,2)],[Ankle(a,3) Heel(a,3)],'Color','k');
line([Heel(a,1) Toe(a,1)],[Heel(a,2) Toe(a,2)],[Heel(a,3) Toe(a,3)],'Color','k');
sl = uicontrol(f,'Style','slider','Min',1,'Max',r,'Sliderstep',[1/(r-1) 10/(r-1)],...
'Callback',{@plot_leg,f,ax,Hip,Knee,Ankle,Toe, Heel});
%sl = uicontrol(f,'Style','slider','Min',1,'Max',r,'Sliderstep',[1 10],...
% 'Callback',{@plot_leg,f,ax,Hip,Knee,Ankle});
sl.Units = 'normalized';
sl.Position = [0.1 0.1 0.8 0.05];
sl.Value = a;
function a = plot_leg(sl,~,f,ax,Hip,Knee,Ank,Toe, Heel)
cla(ax);
val = get(sl,'Value')
a = round(val);
%Get time from slide?
%currentIndex = round(get(src, 'Value'));
figure(f);
%subplot(2, 1, 1);
plot3(ax,Hip(a,1),Hip(a,2),Hip(a,3),'o');
hold on
plot3(ax,Knee(a,1),Knee(a,2),Knee(a,3),'o');
plot3(ax,Ank(a,1),Ank(a,2),Ank(a,3),'o');
plot3(ax,Toe(a,1),Toe(a,2),Toe(a,3),'o');
plot3(ax,Heel(a,1),Heel(a,2),Heel(a,3),'o');
axis equal
% Idea is to plot graph same time
%subplot(2, 1, 2);
%plot(r, Ankle(:,:));
minx = [min(Toe(:,1)) min(Heel(:,1)) min(Ank(:,1)) min(Knee(:,1)) min(Hip(:,1))];
maxx = [max(Toe(:,1)) max(Heel(:,1)) max(Ank(:,1)) max(Knee(:,1)) max(Hip(:,1))];
xlim([min(minx) max(maxx)]);
miny = [min(Toe(:,2)) min(Heel(:,2)) min(Ank(:,2)) min(Knee(:,2)) min(Hip(:,2))];
maxy = [max(Toe(:,2)) max(Heel(:,2)) max(Ank(:,2)) max(Knee(:,2)) max(Hip(:,2))];
ylim([min(miny) max(maxy)]);
minz = [min(Toe(:,3)) min(Heel(:,3)) min(Ank(:,3)) min(Knee(:,3)) min(Hip(:,3))];
maxz = [max(Toe(:,3)) max(Heel(:,3)) max(Ank(:,3)) max(Knee(:,3)) max(Hip(:,3))];
zlim([min(minz) max(maxz)]);
grid on
%
line([Hip(a,1) Knee(a,1)],[Hip(a,2) Knee(a,2)],[Hip(a,3) Knee(a,3)],'Color','k');
line([Knee(a,1) Ank(a,1)],[Knee(a,2) Ank(a,2)],[Knee(a,3) Ank(a,3)],'Color','k');
line([Ank(a,1) Toe(a,1)],[Ank(a,2) Toe(a,2)],[Ank(a,3) Toe(a,3)],'Color','k');
line([Heel(a,1) Ank(a,1)],[Heel(a,2) Ank(a,2)],[Heel(a,3) Ank(a,3)],'Color','k');
line([Heel(a,1) Toe(a,1)],[Heel(a,2) Toe(a,2)],[Heel(a,3) Toe(a,3)],'Color','k');
end

採用された回答

Voss
Voss 2023 年 11 月 20 日
編集済み: Voss 2023 年 11 月 20 日
Create a pushbutton, after creating the slider:
btn = uicontrol(f, ...
'Style','pushbutton', ...
'String','Mark Heel Strike', ...
'Units','normalized', ...
'Position',[0.8 0.15 0.1 0.05], ...
'Callback',{@capture_index,sl});
Its callback can be something like this:
function capture_index(src,~,sl)
idx = get(src,'UserData');
idx(end+1) = get(sl,'Value');
set(src,'UserData',idx);
end
That will store all the indices (i.e., the current slider Value when the button is pressed) in the UserData property of the button. So at any time you can get the stored indices by doing:
idx = get(btn,'UserData');
  4 件のコメント
alexandra ligeti
alexandra ligeti 2023 年 11 月 21 日
Thank you.
I had it below a function so it was not being updated. It all works now. Thank you again for your help!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by