필터 지우기
필터 지우기

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