Stop button to interrupt push botton
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
I have created a push botton (PlotButtonPushed) that automatically increase the value of a slider (sliderChangingFcn) which updates figures data on uifigure().
Now, I would like to create a push/stop button that would interrupt the slider increase and get out of its loop but i am having hard time to implement it.
I tried, as seen in the code below but it does not work. I think I still don't really understand the button's syntax. I also thought of having a state button to replace push and stop buttons but i did not manage to make it either.
Thank you for your help,
function sliderChangingFcn(~,event,data)
% Previous camera angle loaded
CP1 = ax1.CameraPosition;
CP3 = ax3.CameraPosition;
% Update plots and titles with new selection of data
value = round(event.Value);
Vq = interp2(data(:,:,value),Xq, Yq, 'cubic');
%Actualisation InterP surface
heatObj1 = surf(ax1, Xq, Yq, Vq, "EdgeColor", 'none');
set(ax1.Title,'String',sprintf('Electrode Fluorescence Interpolated Surface - Frame #%d',value));
ax1.CameraPosition = CP1;
colormap (ax1, turbo)
%Actualisation InterP colorfill
heatObj2 = pcolor(ax2, Xq, Yq, Vq);
set(heatObj2,'edgecolor','none')
set(ax2.Title,'String',sprintf('Electrode Fluorescence Interpolated Surface - Frame #%d',value));
%Actualisation Raw surface
heatObj3 = surf(ax3, data(:,:,value));
set(ax3.Title,'String',sprintf('Electrode Fluorescence Raw Surface - Frame #%d',value));
ax3.CameraPosition = CP3;
colormap (ax3, turbo)
%Actualisation Raw heatmap
%heatObj4 = heatmap(uip, data(:,:,value),'Colormap', turbo,'CellLabelColor', 'none','ColorLimits', [-400 300]);
heatObj4.ColorData = data(:,:,value);
heatObj4.Title = sprintf('Electrode Fluorescence Heatmap - Frame #%d',value);
end
a=0;
function StopButton(~)
a=1;
end
function plotButtonPushed(a)
uis=2;
while uis < n
Vq = interp2(data(:,:,uis),Xq, Yq, 'cubic');
heatObj1 = surf(ax1, Xq, Yq, Vq, "EdgeColor", 'none');
set(ax1.Title,'String',sprintf('Electrode Fluorescence Interpolated Surface - Frame #%d',uis));
%Actualisation InterP colorfill
heatObj2 = pcolor(ax2, Xq, Yq, Vq);
set(heatObj2,'edgecolor','none')
set(ax2.Title,'String',sprintf('Electrode Fluorescence Interpolated Heatmap - Frame #%d',uis));
%Actualisation Raw surface
heatObj3 = surf(ax3, data(:,:,uis));
set(ax3.Title,'String',sprintf('Electrode Fluorescence Raw Surface - Frame #%d',uis));
%Actualisation Raw heatmap
%heatObj4 = heatmap(uip, data(:,:,value),'Colormap', turbo,'CellLabelColor', 'none','ColorLimits', [-400 300]);
heatObj4.ColorData = data(:,:,uis);
heatObj4.Title = sprintf('Electrode Fluorescence Raw Heatmap - Frame #%d',uis);
uis = uis + t;
pause(0.01)
if a == 1
break
end
end
end
0 commentaires
Réponses (1)
Jiri Hajek
le 7 Oct 2022
There is some confusion in the way you use callbacks.
When you use a state button (or a switch) to interrupt a running for loop, the logical expression of the while loop must receive the information about a change in that value. So the logical expression must be checking the value of a global variable, in this case the Value property of your state button or a switch...
8 commentaires
Allen
le 19 Oct 2022
@Julien Maxime App Designer does a couple of things to facilitate the type of behavior you looking to emulate. Upon running the *.mlapp file containing the classdef code it creates an output argument (app) that is passed along during UIObject callback execution. Additionally, it automatically generates a unique property for each UIObject and assigns the properties to the app argument. This allows the properties of each UIObject to be accessed during the execution of any given callback.
For example, you should be able to access the value of the statebutton during the while-loop even when the state of the button changes, which would provide feedback to end the loop when desired. You can certainly program all of that functionality manually, which would require a lot of effort for applications consisting of more than a handful of UIObjects, but becomes a menial task within App Designer.
Voir également
Catégories
En savoir plus sur Colormaps dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!