how to transfer A PushButton Value to Simulink Model ?

11 visualizaciones (últimos 30 días)
Bin Zhang
Bin Zhang el 2 de Ag. de 2019
Respondida: Shlok el 29 de Oct. de 2024 a las 8:42
IN APP Designer,I put a Pushbutton, In Simulink Model, added a Constant blockes, how to transfer A PushButton Value to Simulink Model ?
thank you a lot!!

Respuestas (1)

Shlok
Shlok el 29 de Oct. de 2024 a las 8:42
Hi Zhang,
You can attach callbacks in App Designer to pass values from input components to a Simulink model when a "PushButton" is clicked.
Within the app, set up an "enter" callback function that uses “set_param” to update the “Constant” block with the specified value.
Here, through the following steps, I have implemented the same:
1. Added a Constant block and a Display block, connected them, and saved the model as sample_model.slx.
2. In App Designer, created a new app.
3. Added a Button with an appropriate name (say, "PushButton") and a Numeric Edit Field (say, "Constant Input").
4. Upon right-click on “PushButton” in App Designer, selected Callbacks > Add PushButtonPushed callback.
5. In the code editor, added the following code inside the callback function:
function PushButtonPushed(app, event)
% ConstantInputEditField is the generated name of ConstantInput in codebase
value = app.ConstantInputEditField.Value;
% Update the Constant block in the Simulink model
set_param('sample_model/Constant', 'Value', num2str(value));
end
6. Run the app, entered a value in the "Constant Input" field, and clicked "PushButton." The “Constant” block in Simulink is updated with the new value.
Hence, using the above-mentioned approach, you can pass the values to the Simulink model from App.
To know more about writing callbacks for GUI in App Designer, you can refer to the following MathWorks Documentation link:

Categorías

Más información sobre Interactive Model Editing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by