Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
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');
disp('Loading data');
%all_data = xlsread(filename,'Trial 1','A2:AS7314');
%[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
% 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';
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;
r = size(frame,1);
if strcmp(sensorside{1,1},cellstr('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'))
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;
f = figure;
ax = axes(f);
ax.Units = 'normalized';
ax.Position = [0.1 0.2 0.8 0.7];
% subplot(2, 1, 1)
hold on
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)
val = get(sl,'Value')
a = round(val);
%Get time from slide?
%currentIndex = round(get(src, 'Value'));
%subplot(2, 1, 1);
hold on
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');

Respuesta aceptada

Voss el 20 de Nov. de 2023
Editada: Voss el 20 de Nov. de 2023
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], ...
Its callback can be something like this:
function capture_index(src,~,sl)
idx = get(src,'UserData');
idx(end+1) = get(sl,'Value');
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 comentarios
alexandra ligeti
alexandra ligeti el 21 de Nov. de 2023
Thank you.
I had it below a function so it was not being updated. It all works now. Thank you again for your help!

Iniciar sesión para comentar.

Más respuestas (0)


Más información sobre Language Fundamentals en Help Center y File Exchange.


Community Treasure Hunt

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

Start Hunting!

Translated by