Reset Constant value in Simulink from Matlab GUI
7 次查看(过去 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.
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!