Browsing to folder from GUIDE on first run of MATLAB gives error
Show older comments
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
Chandrasekhar
on 9 Mar 2015
Hi Raul, You should get that error only if you select cancel without selecting any folder. Otherwise the code should work fine.
Raul
on 9 Mar 2015
Jan
on 9 Mar 2015
Which error message do you get? Which line causes the problem? Did you try to run the command in the command window?
Elias Gule
on 9 Mar 2015
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!!
Raul
on 10 Mar 2015
Answers (0)
Categories
Find more on Graphics Object Properties 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!