Updating guidata between multiple callbacks with one button in Matlab GUI

8 visualizaciones (últimos 30 días)
Niklas
Niklas el 29 de Jun. de 2015
Comentada: Niklas el 30 de Jun. de 2015
Hello!
I'm having problem with updating guidata inbetween callbacks resulting in the error: "Reference to non-existent field 'outflow'."
Here is my code, it would be awesome if someone could point out where I'm doing something wrong! Or atleast the parts that I believe are relevant.
function pushbutton1_Callback(hObject, eventdata, handles)
y = str2double(handles.years);
y = y*365;
years_use = num2str(y);
Q_out = handles.outflow;
set_param(bdroot,'StopTime', years_use);
set_param([bdroot '/Q'], 'Value', Q_out);
sim('River.slx')
The first edit text box where I want to get information from:
function edit1_Callback(hObject, eventdata, handles)
handles.years = get(hObject,'String');
guidata(hObject,handles);
And the second one:
function edit2_Callback(hObject, eventdata, handles)
handles.outflow = get(hObject,'String');
guidata(hObject,handles);
So the problem is, as stated in the first paragraph, that the outflow doesn't get updated as a field. While years does get through. And I don't understand why.
Thank you in advance for your answers!
Regards, Niklas
  1 comentario
Niklas
Niklas el 30 de Jun. de 2015
The problem was solved by adding handles.years and handles.outflow to the opening function. And manually entering the values into the edit textboxs, not trying to run it with the preset value from the GUIDE.

Iniciar sesión para comentar.

Respuestas (1)

Geoff Hayes
Geoff Hayes el 30 de Jun. de 2015
Niklas - I copied and pasted your above code into a simple GUI and did not notice any problems with the callbacks firing properly. So either the above is incomplete or you have perhaps missed a step.
Are you sure that you have entered in data for both the years (in edit1) and the outflow (in edit2) before pressing the push button? Because that is one way that may lead to this error.
You may want to put a breakpoint in the edit2_Callback and verify that it is being called after you have entered data in this control and then give focus to some other control (which should cause the callback to fire).
  1 comentario
Niklas
Niklas el 30 de Jun. de 2015
Thank you for your time!
The problem was solved by adding handles.years and handles.outflow to the opening function. And manually entering the values into the edit textboxs, not trying to run it with the preset value from the GUIDE.

Iniciar sesión para comentar.

Categorías

Más información sobre Simulink en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by