1

I am writing a Matlab code and want to have access to it from different desktops so I am keeping everything in dropbox. I'm wondering if there is a way to tell Matlab the current path without changing the code every time I use a different machine. For example the following line is in my code, but I'd like to make it more general for use on every computer. How can I tell MATLAB the correct path to my file?

[num,txt,raw]= xlsread('C:\Users\Zahra\Documents\dropbox \data.xlsx');
darthbith
  • 18,484
  • 9
  • 60
  • 76
maryam
  • 35
  • 1
  • 6
  • Where is the data stored relative to the place that the MATLAB script is stored? If they're in the same folder you can use `xlsread('data.xlsx')` and it should work on every computer – darthbith Oct 08 '13 at 17:35

2 Answers2

1

You can use a cell array containing your DropBox paths, and test them with isdir embedded in cellfun:

dropbox_path = {'/Users/x/Dropbox/';
    '/Users/xx/Dropbox/';
    '/Users/xxx/Dropbox/'};

dropbox_path = dropbox_path{cellfun(@isdir,dropbox_path)}

Then read your file

[num,txt,raw]= xlsread([dropbox_path 'data.xlsx']);
marsei
  • 7,691
  • 3
  • 32
  • 41
1

Dropbox folder is base64-coded at host.db file in a folder that is situated at AppData folder in Windows. I'm not shure if it is crossplatform, but works at my system and my dropbox.

%http://www.mathworks.com/matlabcentral/fileexchange/15886-get-application-data-directory/content/getapplicationdatadir.m 
%http://www.mathworks.com/matlabcentral/fileexchange/12907-xmliotools/content/base64decode.m
f = getapplicationdatadir('dropbox', 0, 0);
hostdb = fopen([f '/host.db']);
%skip line
fgetl(hostdb);
s = fgetl(hostdb);
path = sprintf('%s', base64decode(s));
cd(path);
Dmitry Galchinsky
  • 2,181
  • 2
  • 14
  • 15