Search code examples
matlabpathdirectorysharedropbox

How to assign current directory to a dropbox folder


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');

Solution

  • 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);