Browse Button in GUIDE issue

Hi, I have a callback function for a Browse button (to select a file) in a GUIDE generated fig:
% --- Executes on button press in browse_pushbutton.
function browse_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to browse_pushbutton (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({'*.dat;*.txt','Input Files (*.dat, *.txt)';'*.*','All Files (*.*)'},'Select a file for input');
if ~isequal(FileName,0)
set(handles.path_text,'String',[PathName FileName]);
end
Issue I am having is after I select the file in the uigetfile window and click on open, I get the following error:
Attempt to reference field of non-structure array.
Error in compute_ENOB>browse_pushbutton_Callback (line 302)
set(handles.path_text,'String',[PathName1 FileName1]);
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in compute_ENOB (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)compute_ENOB('browse_pushbutton_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
I am not sure what is wrong.

1 commentaire

Leor Greenberger
Leor Greenberger le 4 Oct 2011
I just repuposed the browse button to do this:
function browse_pushbutton_Callback(hObject, eventdata, handles)
set(handles.path_text,'String','blah');
When I save the .m file and run the .fig file, it works. But if I restart MATLAB and try it again, it errors!

Connectez-vous pour commenter.

 Réponse acceptée

Fangjun Jiang
Fangjun Jiang le 4 Oct 2011

0 votes

In your code, it says:
set(handles.path_text,'String',[PathName FileName])
In the error message, it says:
set(handles.path_text,'String',[PathName1 FileName1])
Wrong variable name?

4 commentaires

Leor Greenberger
Leor Greenberger le 4 Oct 2011
That was a typo. I appended the 1 to the variable name to see if it would work, but I had already copied the previous error message before I made the changes. As validation, I repurposed the browse button to do the following:
function browse_pushbutton_Callback(hObject, eventdata, handles)
set(handles.path_text,'String','blah');
and this works if I edit the .m file, save it, and run the .fig. But if I were to exit MATLAB, and then run the .fig again, it would produce that error message. Strange.
Leor Greenberger
Leor Greenberger le 4 Oct 2011
I even just deleted the edit text box, created a new one, with a new tag, and tried to the browse pushbutton callback function to:
set(handles.path_text,'String','blah');
again, it worked right after, but when I restarted MATLAB, it produced an error:
Attempt to reference field of non-structure array.
Error in compute_ENOB>browse_pushbutton_Callback (line 304)
set(handles.path_text_,'String','blah');
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in compute_ENOB (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)compute_ENOB('browse_pushbutton_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
Fangjun Jiang
Fangjun Jiang le 4 Oct 2011
Don't double-click the .fig file to open it. Is that what you did? See
http://www.mathworks.com/matlabcentral/answers/17138-able-to-run-gui-from-guide-command-interface-but-not-when-opening-fig-straight-in-folder
Leor Greenberger
Leor Greenberger le 4 Oct 2011
Yes, I double clicked! Funny how someone just had the same issue only 4 days ago. Thanks!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur App Building dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by