MATLAB Examples

Control a Parameter Value with Callback Button Blocks

This example models control of a system that consists of two masses attached on either side of a spring. A control loop damps the oscillation of the spring that results when an external force acts on the system. The model uses Callback Button blocks to provide an interface for you to adjust the frequency of the external force before and during simulation.

Contents

Explore the Model

The model for this example adds two Callback Button blocks, labeled Frequency + and Frequency - to the Double Mass-Spring System model. When you simulate the model, an animation visualizes the system.

Click the button labeled Frequency + to increase the oscillation frequency. When you adjust the frequency of the external force, the Callback Button block displays a message in the command window indicating the new frequency value. You can adjust the parameter during a simulation and while the model is idle.

Both Callback Button blocks in this model are configured with a ClickFcn that responds to your clicks and a PressFcn that executes when you press the Callback Button block. Double-click the Frequency + Callback Button block to view its parameters.

When you click the Frequency + Callback Button block, the ClickFcn increases the frequency of the external force by 0.1. If you press the Callback Button block for more than the 500 ms Press Delay, the PressFcn increases the frequency of the external force by 0.1 every second.

See Also

docid:simulink_ref.mw_3efc6483-6b68-448c-9980-a6ade762d12a

docid:simulink_ref.mw_68fe6b5b-f3e2-4934-b10b-8da199a736ee