While running the following gui code i got this error : Undefined function or variable 'hObject'. Error while evaluating uicontrol Callback

1 view (last 30 days)
satendra kumar
satendra kumar on 4 Nov 2012
if true
% code
endfunction varargout = faltu(varargin)
% FALTU MATLAB code for faltu.fig
% FALTU, by itself, creates a new FALTU or raises the existing
% singleton*.
%
% H = FALTU returns the handle to a new FALTU or the handle to
% the existing singleton*.
%
% FALTU('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in FALTU.M with the given input arguments.
%
% FALTU('Property','Value',...) creates a new FALTU or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before faltu_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to faltu_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help faltu
% Last Modified by GUIDE v2.5 04-Nov-2012 10:59:37
% Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @faltu_OpeningFcn, ... 'gui_OutputFcn', @faltu_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end
if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT
% --- Executes just before faltu is made visible. function faltu_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 faltu (see VARARGIN)
% Choose default command line output for faltu handles.output = hObject;
% Update handles structure guidata(hObject, handles);
% UIWAIT makes faltu wait for user response (see UIRESUME) % uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line. function varargout = faltu_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure varargout{1} = handles.output;
% --- Executes on button press in load. function load_Callback(hObject, eventdata, handles) % hObject handle to load (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) handles.fileName=uigetfile('*.xlsx') guidata(hObject,handles)
setPopupmenuString(handles.popupmenuY,eventdata,handles) setPopupmenuString(handles.popupmenuX,eventdata,handles)
set(handles.popupmenuX,'callback','faltu(''updateAxes'',hObject,eventdata,guidata(hObject))') set(handles.popupmenuY,'callback','faltu(''updateAxes'',hObject,eventdata,guidata(hObject))')
function setPopupmenuString(hObject, eventdata,handles) fileName=handles.fileName; [numbers, colNames]= xlsread(fileName); set(hObject,'string',colNames);
function[x y] = readexcelfile(fileName,xcol,ycol) a=xlsread(fileName); x=a(:,xcol); y=a(:,ycol);
function updateAxes(hObject, eventdata,handles) xcol=get(handles.popupmenuX,'values'); ycol=get(handles.popupmenuY,'values'); fileName=handles.fileName; [x y] = readexcelfile(fileName,xcol,ycol) plot(handles.axes1,x,y)
% --- Executes on selection change in popupmenuy. function popupmenuX_Callback(hObject, eventdata, handles) % hObject handle to popupmenuy (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenuy contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenuy
% --- Executes during object creation, after setting all properties. function popupmenuX_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenuy (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end
% --- Executes on selection change in popupmenuY. function popupmenuY_Callback(hObject, eventdata, handles) % hObject handle to popupmenuY (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenuY contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenuY
% --- Executes during object creation, after setting all properties. function popupmenuY_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenuY (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end
  1 Comment
Jan
Jan on 4 Nov 2012
Please learn how to format code in this forum. This has been explained repeatedly and I'm sure, you can find one of the descriptions easily.
An answer is much easier, if you post only the relevant part of the code. The error message contains the line number, where the problem occurs, and you should mention this line explicitly. Otherwise an answer requires guessing and this is a bad strategy.
The thread Answers: A guide to tags explains how to choose meaningful tags. Tags are used to classify questions, therefore repeating the title is not useful.

Sign in to comment.

Answers (1)

Jan
Jan on 4 Nov 2012
I guess, that this causes the problem:
set(handles.popupmenuX, 'callback', ...
'faltu(''updateAxes'',hObject,eventdata,guidata(hObject))')
Callbacks, which are defined as strings, are executed in the base workspace. The base workspace, which is active when you type commands in the command window, does not know the local variable "hObject". "eventdata" is created by the event handler dynamically, therefore you cannot set this statically, especially not in a string callback. I assume, you want this:
set(handles.popupmenuX, 'callback', ...
{@faltu, 'updateAxes', guidata(hObject)})
But finally I stress again, that this answer is based on guessing only and I cannot test it.

Community Treasure Hunt

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

Start Hunting!