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