- Create an MLAPP with input fields for “k” and “m”. These could be numeric edit fields or sliders, depending on your preference.
- Add a button to the app that, when clicked, will run the simulation with the specified parameters.
- Create a callback function for the button to update the parameters using “set_param”. Here is an example of how you might implement this:
How to connect value in app designer to simulink
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have Simscape Simulink Model. I set the parameter of Spring Stiffness is k, Mass is m.
How to add value from Appdesign and Simulink ?
Thank you!
0 comentarios
Respuestas (1)
Samay Sagar
el 20 de Ag. de 2024
Hi Thai,
I understand that you want to pass values for certain parameters (spring stiffness and mass) from a MLAPP to a Simulink model. Here is how you can create such an app:
function UpdateParametersButtonPushed(app, event)
% Retrieve parameter values from the app
k_value = app.SpringStiffnessEditField.Value;
m_value = app.MassEditField.Value;
% Set the parameters in the Simulink model
% Replace 'YourSpringBlock' and 'YourMassBlock' with the actual block paths
set_param('spring_mass_model/YourSpringBlock', 'Stiffness', num2str(k_value));
set_param('spring_mass_model/YourMassBlock', 'Mass', num2str(m_value));
% Run the simulation
simOut = sim('spring_mass_model', 'SimulationMode', 'normal');
% Extract the results if needed
time = simOut.tout;
outputs = simOut.yout{1}.Values.Data;
end
Alternatively, you can also configure your model to take the parameter values from the base workspace. In the above callback function, you can use “assignin” to update the corresponding variable as follows:
assignin('base', 'mass', m_value);
Ensure that the corresponding blocks take these values as variables from the workspace by specifying the same names in the block parameters.
If you want to pass input signals to your model from your app, you can refer the following documentation to prepare your input data:
For more information about “set_param” and “assignin”,you can refer the following documentation:
0 comentarios
Ver también
Categorías
Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!