Reset Constant value in Simulink from Matlab GUI

8 次查看(过去 30 天)
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.

采纳的回答

Abhi Sundararaman
Abhi Sundararaman 2017-10-12
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by