Filter löschen
Filter löschen

Reset Constant value in Simulink from Matlab GUI

8 Ansichten (letzte 30 Tage)
monkey_matlab am 10 Okt. 2017
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)
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.

Akzeptierte Antwort

Abhi Sundararaman
Abhi Sundararaman am 12 Okt. 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.

Weitere Antworten (0)


Mehr zu Simulink Functions finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by