Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

Default path for GUI

Asked by Lalit Patil on 5 Feb 2013

I have created a GUI. I want to do like Whenever that GUI starts it should only execute files from predefined path in it..

For that i want to assign path for it.. So, where i have to assign it and what will be command.?

Whether at below opening function or somewhere else.?

0 Comments

Lalit Patil

Products

No products are associated with this question.

1 Answer

Answer by Jan Simon on 5 Feb 2013
Edited by Jan Simon on 5 Feb 2013

Yes, you can hard code a path and use cd() to change into this path. It would be safer to store this path in the handles struct and use absolute file names instead, because otherwise and cd() command in a Timer, another GUI or in the command line would confuse your GUI application.

It is user friendly not to hard code a path in the sourcecode of a GUI. Better add a textfield to the GUI, which conatins the current focussed folder and allow the user to change it. Whenever the value is modified, it is written as MAT file to the folder prefdir, such that at opening the GUI you can obtain the former value from this location again:

% In Opening function:
try
  Data = load(fullfile(prefdir, 'MyGUIFolder.mat'));
  myFolder = Data.myFolder;
catch  % Not existing yet:
  myFolder = pwd;
end
handles.myFolder = myFolder;
guidata(figureHandle, myFolder);
% In callback:
function myXYZ_callback(hObject, EventData, handles)
handles = guidata(hObject);
disp(handles.myFolder);
% In callback of the text field, which contains the folder:
function myText_callback(hObject, EventData, handles)
myFolder = get(hObject, 'String')
if exist(myFolder, 'dir') ~= 7
  set(hObject, 'Color', 'r');  % Or what ever
  return;
end
set(hObject, 'Color', 'k');  % Or what ever
save(fullfile(prefdir, 'MyGUIFolder.mat'), 'myFolder');

0 Comments

Jan Simon

Contact us