I am using setappdata() and getappdata() in my code and I'm getting this error. PLz help me out, how to remove this error? what will be the correct code?

2 views (last 30 days)
function varargout = Trial(varargin) % TRIAL M-file for Trial.fig % TRIAL, by itself, creates a new TRIAL or raises the existing % singleton*. % % H = TRIAL returns the handle to a new TRIAL or the handle to % the existing singleton*. % % TRIAL('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in TRIAL.M with the given input arguments. % % TRIAL('Property','Value',...) creates a new TRIAL or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before Trial_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to Trial_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 Trial
% Last Modified by GUIDE v2.5 26-Mar-2014 15:02:25
% Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @Trial_OpeningFcn, ... 'gui_OutputFcn', @Trial_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 Trial is made visible. function Trial_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 Trial (see VARARGIN)
% Choose default command line output for Trial handles.output = hObject;
% Update handles structure guidata(hObject, handles);
% UIWAIT makes Trial wait for user response (see UIRESUME) % uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line. function varargout = Trial_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 pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) [filename, pathname] = uigetfile('*.jpg', 'Pick an M-file'); filename=strcat(pathname,filename); I1 = imread(filename); I1 = imshow(I1,'Parent',handles.axes1); setappdata(handles.pushbutton1,'img',I1)
% --- Executes on button press in pushbutton2. function pushbutton2_Callback(hObject, eventdata, handles) % hObject handle to pushbutton2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) rg = rgb2gray(I1); rg1 = imadjust(rg) rg1 = imshow(rg1,'Parent',handles.axes2);
--------------------------------------------------------------------------------------------
ERROR:
??? Undefined function or variable 'I1'.
Error in ==> Trial>pushbutton2_Callback at 92 rg = rgb2gray(I1);
Error in ==> gui_mainfcn at 96 feval(varargin{:});
Error in ==> Trial at 42 gui_mainfcn(gui_State, varargin{:});
Error in ==> guidemfile>@(hObject,eventdata)Trial('pushbutton2_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback

Answers (1)

Image Analyst
Image Analyst on 19 Apr 2014
I1 was never defined in pushbutton2's callback. All variables are local unless you make them global explicitly or use functions like getappdata to pass them around. See the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!