MATLAB: In gui,I want to display an image,to use it’s path with an other pushbutton and then to display a result in a text edit box

callbackguipushbuttontext edit box

that's what i did so far and it doesn't work,i get this error message:
??? Reference to a cleared variable handles.
Error in ==> SimpleGui>ImPr_Callback at 119 set(handles.ImSelect,'String',strcat(pathname,filename));Str=get(handles.ImSelect,'String');
Error in ==> gui_mainfcn at 96 feval(varargin{:});
Error in ==> SimpleGui at 42 gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)SimpleGui('ImPr_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
my code:
% — Executes on button press in ImSelect. function ImSelect_Callback(hObject, eventdata, handles) % hObject handle to ImSelect (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'); selected=sprintf('%s',filename); i=imread(selected); %reading your .jpg image axis(handles.axes1); %setting the image in axes1 component -look at thag property of axes which is default axes1 imshow(i)
% — Executes on button press in ImPr. function ImPr_Callback(hObject, eventdata, handles) % hObject handle to ImPr (see GCBO) % eventdata reserved – to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) clc,clear,close all %A='C:\Users\Sagipc\Desktop\igal.jpg'; set(handles.ImSelect,'String',strcat(pathname,filename));Str=get(handles.ImSelect,'String'); pic=double(imread(Str,'jpg')); … … .. beta=num2str(pd); … … set(handles.GetBeta, 'String', beta);
please help.

Best Answer

pathname is in ImSelect_Callback() but not in ImPr_Callback().
Either put
global pathname;