How to recongnize a field in GUI
Info
This question is closed. Reopen it to edit or answer.
Show older comments
I was about to practice my GUI exercise. For my GUI, I added the following codes in GUI opening function so that all the components recognized the function.
GUI code
function Exercise2_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to Exercise2 (see VARARGIN)
% Choose default command line output for Exercise2
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
x_str=get(handles.XEditStr,'string');
y_str=get(handles.YEditStr,'string');
x=str2num(x_str);
y=eval(y_str);
handles.Line_handle=feval('plot',x,y);
CurrentLineColor=get(handles.Line_handle,'color');
set(handles.RSlid,'value',CurrentLineColor(1));
set(handles.GSlid,'value',CurrentLineColor(2));
set(handles.BSlid,'value',CurrentLineColor(3));
set(handles.RSlidValTxt,'string',num2str(CurrentLineColor(1)));
set(handles.GSlidValTxt,'string',num2str(CurrentLineColor(2)));
set(handles.BSlidValTxt,'string',num2str(CurrentLineColor(3)));
However, It did not work and gave an error as follows.
Error Message
Reference to non-existent field 'Line_handle'.
Error in GUIDemo>RSlid_Callback (line 153)
CurrentColorVal=get(handles.Line_handle,'color');
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in GUIDemo (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)GUIDemo('RSlid_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
How to solve this problem and work my GUI correctly? Please give me your answers. Thank you.
Answers (1)
Walter Roberson
on 14 Feb 2017
The error message you show is from a callback whose code you do not show.
However, we predict that you should move
% Update handles structure
guidata(hObject, handles);
to after the code that you posted.
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!