Hi everyone, I have got a Problem with my GUI. My program has two buttons, I use the first button to choose a specific file in subfolder.
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, filterindex] = uigetfile( ...{ '*.mat','MAT-files (*.mat)'; ... '*.slx;*.mdl','Models (*.slx, *.mdl)'; ... '*.txt','Text Files (*.txt)'; ... '*.*', 'All Files (*.*)'}, ... 'Pick a file', ... 'MultiSelect', 'on',... '..\Schaltungen\');if isequal(filename,0) disp('User selected: Cancel')else disp(['User selected ', fullfile(pathname, filename)])endglobal fname;assignin ('base','fname',filename);%assignin ('base','path',pathname);
%fname = strcat(pathname,filename);
%assignin ('base','fname',fname);
%callback of button 1
handles.fname = fname;guidata(hObject, handles)
When I declare the button 2 with containing the m.file , the code in m.file is
[Name, N1, N2, arg3]=textread(fname,'%s %s %s %s ');
in which to process variable fname which i have got already at button 1. And the code for callback in Button 2 is
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)global fname;fname = 'handles.fname';
And my program got some errors,
Error using textread (line 165)File not found.Error in scam (line 13)[Name, N1, N2, arg3]=textread(fname,'%s %s %s %s ');Error in demogui>pushbutton2_Callback (line 112)scamError in gui_mainfcn (line 95) feval(varargin{:});Error in demogui (line 42) gui_mainfcn(gui_State, varargin{:});Error in @(hObject,eventdata)demogui('pushbutton2_Callback',hObject,eventdata,guidata(hObject))Error while evaluating uicontrol Callback
I don't know exactly what happening with this program. Hope to receive your supports.
Best Answer