Selecting radio button resets GUI [GUIDE, R2017b]

1 次查看(过去 30 天)
Hello,
I have a GUI with several edit boxes which sow the names of files which have been selected by the user. I aso have some radio buttons which dictate what operation to complete on the data which is loaded vvia the GUI.
When I have loaded the data and then click a radio button which was not the default, all the edit boxes clear and it seems as though the GUI is reinitialised. I have not used the radio button group call back for selectionChanged. All I do is check which radio button has been clicked when it comes to performing the calculations. Does anyone know why the radio button keeps reinitialising the GUI?
The code for initialising the GUI objects I have written is:
function defaultVals(hObject, handles)
%
% This function takes the handle to the GUI figure, and structure with
% handles and user data and sets the values of the various
% objects on the GUI.
% Call this function in the Openingfunction of the GUI to set initial
% values for the GUI objects.
set(handles.textPath,'string','No file loaded.'); % sets default value of textFile
set(handles.textFile,'string','No file loaded.'); % sets default value of textData
set(handles.checkbox1 , 'Enable','off'); % disable checkbox1;
I placed this function in the OpeningFcn. After using the dbstack (Thanks to Jan Simon's suggestion) I found the following call stack was produced when I placed 'dbstack' in my defaultVals function:
In VoltageResonance>defaultVals (line 272)
In VoltageResonance>VoltageResonance_OpeningFcn (line 58)
In gui_mainfcn (line 220)
In VoltageResonance (line 42)
In matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)VoltageResonance('trainConfigGroup_SelectionChangedFcn',get(hObject,'SelectedObject'),eventdata,guidata(get(hObject,'SelectedObject')))
It appears that the function matlab.graphics.internal.figfile.FigFile/read causes the GUI to be run again but I am not sure where that function arises from by changing a radio button. Kind regards, TJ

采纳的回答

Jan
Jan 2018-1-4
Then the callback of the radio button contains some code, which initializes the contents of the GUI. Without seeing the code, we cannot guess, which command it is. But you can find this out easily using the debugger: https://www.mathworks.com/help/matlab/matlab_prog/debugging-process-and-features.html Set a breakpoint in the callback and step through the code line by line. You will find, which command causes the reset. Finally remove this command.
  9 个评论
Jan
Jan 2018-8-3
@Duijnhouwer: Please post some code which reproduces the behavior you observe.
Image Analyst
Image Analyst 2018-8-3
Sounds like user error to me. Why would you remove the callback that runs when you click on a radio button???

请先登录,再进行评论。

更多回答(1 个)

Image Analyst
Image Analyst 2018-1-5
Put the function call in the OutputFcn() rather than the OpeningFcn() and see if that helps.

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by