Stop button to interrupt push botton

3 ビュー (過去 30 日間)
Julien Maxime
Julien Maxime 2022 年 10 月 7 日
コメント済み: Allen 2022 年 10 月 19 日
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

回答 (1 件)

Jiri Hajek
Jiri Hajek 2022 年 10 月 7 日
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 件のコメント
Julien Maxime
Julien Maxime 2022 年 10 月 7 日
Well i am not gonna restart my whole interface on AppDesigner for this small problem. Thanks for your kind help anyway.
Allen
Allen 2022 年 10 月 19 日
@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.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by