How to update plot delay value based on uifigure slider
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I am trying to find the electromechanical delay between an EMG signal and a Force signal produced by a muscle. I tried doing this using cross-correlation but was not satisfied with the results. I am new to GUIs in Matlab and could use a little help.
The code below is producing the following Figure that looks okay, however it is not updating based on the slider like I am intending it to. I am trying to slide the yellow traces left/right to align them with the blue traces. The top row is the entire signal, the bottom row is a zoomed in and filtered version of the signal.
Right now, as I move the slider it does not update the variable "EMdelay" in the code. Is it possible to update this delay variable and allow the graphs to slide left/right based on the value of the slider and then return that value once the Figure is closed? Do I need to be updating an axis or figure variable instead to make this work?
Thanks in advance.
function EMdelay = delaySlider(fsamp, filtCST, iEMG, force, fluctForce, steadyEMGInd, titleString)
%delaySlider creates a uifigure to slide EMG signal along the force trace
% to find the electromechanical delay between the signals.
time = 0:1/fsamp:(length(force)-1)/fsamp;
time10 = 0:1/fsamp:10-1/fsamp;
EMdelay = 0;
fig = uifigure("Name",titleString);
g = uigridlayout(fig);
g.RowHeight = {'1x','1x','fit'};
g.ColumnWidth = {'1x'};
ax1 = uiaxes(g);
ax2 = uiaxes(g);
plot(ax1,time,force/max(abs(force)),...
time,iEMG/max(abs(iEMG)),...
time+EMdelay/fsamp,iEMG/max(abs(iEMG)),...
'LineWidth',2);
legend(ax1,'force','iEMG original','iEMG delayed');
plot(ax2,time10,fluctForce/max(abs(fluctForce)),...
time10,filtCST(steadyEMGInd(1):steadyEMGInd(2)-1)/...
max(abs(filtCST(steadyEMGInd(1):steadyEMGInd(2)))),...
time10,filtCST(steadyEMGInd(1)+EMdelay:steadyEMGInd(2)+EMdelay-1)/...
max(abs(filtCST(steadyEMGInd(1)+EMdelay:steadyEMGInd(2)+EMdelay-1))),...
'LineWidth',2);
legend(ax2,'force flucts','original CST flucts','delayed CST flucts');
sld = uislider(g,...
"Limits",[-500 500],...
"Value",0);
sld.ValueChangingFcn = @(src,event) updateEMdelay(src,event,EMdelay);
uiwait(fig);
end
function updateEMdelay(src,event,EMdelay)
EMdelay = event.Value;
end
0 Commenti
Risposte (1)
Himanshu
il 20 Mar 2024
Hello Taylor,
I understand that you are trying to update the plot delay value based on a uifigure slider in MATLAB App Designer.
The issue you are encountering is due to how MATLAB handles variable scope and updates in GUIs. The "EMdelay" variable within the "updateEMdelay" function is updated, but this change is not reflected in the main function or the plots because the scope of "EMdelay" in "updateEMdelay" is local to that function only. Additionally, the plots themselves are not being instructed to redraw with the new delay value.
To solve this problem, you can update the plots within the "updateEMdelay" function whenever the slider value changes. This involves recalculating the data for the plots with the new delay and then using the "set" function or similar methods to update the existing plot objects.
Please refer to the below documentation to learn more about "set" function in MATLAB.
I hope this helps.
0 Commenti
Vedere anche
Categorie
Scopri di più su Develop uifigure-Based Apps in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!