Browsing to folder from GUIDE on first run of MATLAB gives error

Dear All, I am getting strange error when using GUIDE on trying to browse to a data folder, ONLY on the first time MATLAB runs.
Basically there is a button on top (tag:pushbuttonbrowse), which is used to browse to a data sub-folder on the Desktop which is contained in a main data folder. Once folder is set, then other buttons can be pressed to process files in that sub-folder.
When I start matlab, type in GUI_Name to start the GUI and press that browse button - it gives an error saying something like filepath cannot be null and it cannot use 'cd' command on that. Consequently '0' string is shown as the button text. On starting MATLAB, if i change the current folder to desktop or the main data folder (Desktop/Data) and then push the button, then the message box is shown and a select folder dialogue opens (uigetdir) and things go smoothly. The current data folder path is shown on the button text.
I also tried to add in a line to change the current folder to the main data folder as the first line in the code section for function pushbuttonbrowse_Callback, but that also did not make a difference. I did the same in function SSVEP_GUI_OpeningFcn, so that it points to the main data folder as soon as the GUI is made visible, but that also does not help.
The first time MATLAB starts, its current folder is somewhere in the Documents folder.
Any suggestions to rectify this ? Thanks R
Code is something like this ------------------------------------
% *Begin initialization code - DO NOT EDIT*
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @SSVEP_GUI_OpeningFcn, ...
'gui_OutputFcn', @SSVEP_GUI_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 SSVEP_GUI is made visible.
*function SSVEP_GUI_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 unrecognized PropertyName/PropertyValue pairs from the
% command line (see VARARGIN)
% Choose default command line output for SSVEP_GUI
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes SSVEP_GUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
*function varargout = SSVEP_GUI_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 pushbuttonbrowse.*
function pushbuttonbrowse_Callback(hObject, eventdata, handles)
% hObject handle to pushbuttonbrowse (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
waitfor(msgbox('Please choose the Folder with files to process'));
% select folder directly
filepath = uigetdir('Choose a Folder with data files');
set(handles.pushbuttonbrowse, 'String', filepath);
cd(filepath);
----------------------------------

6 Comments

Hi Raul, You should get that error only if you select cancel without selecting any folder. Otherwise the code should work fine.
Yes, its the same error which comes if i click cancel. But in this case, it occurs after the first run of MATLAB and it does not even get to the msgbox or the uigetdir parts, just shows the error.
Which error message do you get? Which line causes the problem? Did you try to run the command in the command window?
Hi Raul, plz look at the help doc for uigetdir; The first input to uigetdir must be a valid path; unless of course if you invoke the zero input version of uigetdir. Otherwise, the error your are experiencing might be because of a corrupt .fig file. Just a thought!!
Thanks Elias for your comment. By corrupt .fig file, do you mean the GUI fig file associated with the .m code ? But how can i confirm this, because if i just transfer all the code to a new GUI, the error might be transferred as well. and to make a new gui would be quite a bit of work !
Jan Simon, The exact error message is
Error using cd
Argument must contain a string.
Error in S_GUI>pushbuttonbrowse_Callback (line 89)
cd(filepath);
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in S_GUI (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)S_GUI('pushbuttonbrowse_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
The exact line giving the error is the last one in the code above
cd(filepath)

Sign in to comment.

Answers (0)

Categories

Find more on Graphics Object Properties in Help Center and File Exchange

Asked:

on 9 Mar 2015

Edited:

on 12 Mar 2015

Community Treasure Hunt

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

Start Hunting!