Azzera filtri
Azzera filtri

Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

How to recongnize a field in GUI

1 visualizzazione (ultimi 30 giorni)
Chang Jae Kim
Chang Jae Kim il 14 Feb 2017
Chiuso: MATLAB Answer Bot il 20 Ago 2021
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.

Risposte (1)

Walter Roberson
Walter Roberson il 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.

Questa domanda è chiusa.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by