Reset Constant value in Simulink from Matlab GUI

8 visualizaciones (últimos 30 días)
monkey_matlab
monkey_matlab el 10 de Oct. de 2017
Respondida: Abhi Sundararaman el 12 de Oct. de 2017
Hello,
In this very simplistic model of just a constant in Simulink, I wanted to RESET the value to zero by hitting the RESET button. Here is the callback code for the pushbutton control
% --- Executes on button press in RESET.
function RESET_Callback(hObject, eventdata, handles)
% hObject handle to RESET (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set_param('email_const/Constant','Value',0);
This is a screenshot of the Simulink (just a constant block).
How to go about successfully resetting the value to zero when the pushbutton is pressed. For your convenience, I have attached all the necessary files. Thanks.

Respuesta aceptada

Abhi Sundararaman
Abhi Sundararaman el 12 de Oct. de 2017
This is a very common issue, and I completely understand why!
The issue here is because in line 81 of "change_const.m", the value of Constant is being set to 0, rather than '0'.
When you use setparam, the value for the constant block should actually be a character array containing a value, rather than an actual value! I know that's very unintuitive, but the solution is pretty straightforward from here.
To fix your issue, just replace line 81 with the following:
set_param('email_const/Constant','Value','0'); %note that the 0 should be enclosed in single quotes.

Más respuestas (0)

Categorías

Más información sobre Simulink Functions 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