Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to realize the pause function in MATLAB GUI Animation demonstration

Shulou Source: shulou.com Published: 2022-06-01 06:30:04 10月22日 Update

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!

Tags: Buttons layout step size function animation article change presentation content function build loop not much again dynamic coordinate coordinate system most width idea Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Shulou Information Redmi MariaDB Shulou Technology