Reset Constant value in Simulink from Matlab GUI

조회 수: 8 (최근 30일)
monkey_matlab
monkey_matlab 2017년 10월 10일
답변: Abhi Sundararaman 2017년 10월 12일
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