In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to achieve the pause function in the MATLAB GUI animation demonstration, I believe most people do not know much about it, so share this article for your reference. I hope you will gain a lot after reading this article. Let's learn about it together.
Let's start with a brief line of thought:
Design this pause button as togglebutton
Put the changed step size into the UserData of this togglebutton
When you click start, execute an endless loop, each of which takes the UserDatavalue of the pause button as the change step of the dynamic display data.
When you click the pause button, if the button is pressed, the value of its UserData is changed to 0, so the step size is unchanged, which is equivalent to pausing the animation.
When you click the button again, the button pops up and the value of its UserData is changed to the original step size.
Function MainFigure ()
Clc
Close all
Create main window
HMain = figure ('NumberTitle',' off', 'Name',' suspend function Demo', 'Menubar',' none', 'Toolbar',' none')
% create general layout
Lay = uiextras.VBox ('Parent', hMain)
Create sublayout 1
Lay1 = uiextras.HBox ('Parent', lay)
Create sublayout 2
Lay2 = uiextras.HBox ('Parent', lay)
% create coordinate system
AxMain = axes ('Parent', lay1,' NextPlot', 'replace',' XTick', [], 'YTick', [])
Lay1.Widths =-1
% create start button
Start_btn = uicontrol ('Parent', lay2,...
'Style', 'pushbutton',...
'String',' start')
% create pause button
Pause_btn = uicontrol ('Parent', lay2,...
'Style', 'togglebutton',...
String', 'pause',...
'UserData', 0.001)
% sets the width of the controls in layout 2
Lay2.Widths = [- 1,-1]
% set up the overall layout
Lay.Heights = [- 1,32]
% set callback function
Start_btn.Callback = {@ callback_start_btn, pause_btn, axMain}
Pause_btn.Callback = {@ callback_pause_btn}
End
Function callback_start_btn (~, pause_btn, ax)
X =-2: 0.01: 2
P = 0.001; initial value of% power
While true
If p > 4 | | p < 0
Pause_btn.UserData =-pause_btn.UserData
End
% get the change step of the power
P = p + pause_btn.UserData
% calculates the function value after the current power operation
Y = abs (x). ^ p
Plot (x, y, 'Parent', ax)
Pause (0.001)
Drawnow
End
End
Function callback_pause_btn (this, ~)
If this.Value = = 1
This.UserData = 0
This.String = 'continue'
Else
This.UserData = 0.001
This.String = 'pause'
End
End
The above is all the contents of the article "how to achieve the pause function in MATLAB GUI Animation demonstration". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.