Comment créer une variable utilisable dans un block simulink

2 次查看(过去 30 天)
Dans simulink, j'ai une constante dont la valeur est modifiée par le bias d'un "radio button" c'est à dire un questionnaire à choix multiple. Cette valeur est utilisée dans une partie de la simulation qui concerne un diagramme d'état mais j'aimerai aussi me servir de cette valeur comme paramètre dans un bloc de type "gear=engrenage". Comment puis-je faire cela d'après-vous?

回答(1 个)

Ayush
Ayush 2024-5-22
Hi Steve,
I will be answering your query in English, since I am not proficient in French. From what I have gathered from your description, it seems that you want to use a value from a state diagram as a block parameter in your simulation. You have also mentioned about changing a constant value using a “radio button” which I would be addressing briefly in the steps to follow to achieve the desired result:
Creating and linking radio button to Simulink model
You would have to ensure that there is a GUI element setup for the user to interact with and change the value of the constant. This can be done using MATLAB’s App Designer or programmatically using “uicontrol”.
Please refer to the below documentations to know more about radio button in MATLAB's App Designer and its programmatic use:
Using the value in Simulink
For using the changed value in a state diagram for controlling the flow or state of simulation you can either use “From Workspace” block or “Data Store Memory” to access the variable into the Simulink Model.
Please refer to the below documentation to know more about the "From Workspace" block or "Data Store Memory":
To further the use of this value and the corresponding variable and setting a block parameter with it, you can use the “set_param” function. This function can then be linked to the callback function of the radio button to trigger whenever the value of the constant is changed . Here is an example code for your reference:
set_param('yourModelName/yourBlockPath', 'gear', num2str(newValue))
% this newValue can either be accessed from the workspace or the
% "Data Store Memory" and not necessarily via the callback depending on the
% flow of your simulation.
Please refer to the below documentation to know more about the "set_param" function:
Hope this helps!

标签

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!