Info

此问题已关闭。 请重新打开它进行编辑或回答。

How to recongnize a field in GUI

1 次查看(过去 30 天)
Chang Jae Kim
Chang Jae Kim 2017-2-14
关闭: MATLAB Answer Bot 2021-8-20
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.

回答(1 个)

Walter Roberson
Walter Roberson 2017-2-14
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.

此问题已关闭。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by