Search code examples
matlabsaveexport-to-excel

Writing table to specific folder


I am wondering how one can save a table using the following

 filename_excel = [ name '_N' num2str(1) '.xlsx'];
 writetable(Table,filename_excel,'Sheet', 3, 'Range','A5');

to a specific directory/folder other than the current folder?


Solution

  • Change filename_excel to

    filename_excel = [my_directory name '_N' num2str(1) '.xlsx'];
    

    where

    my_directory = 'C:\some\directory\structure\';
    

    Alternatively (though use the first solution if possible) you can go:

    current_dir = cd;
    cd my_directory;
    
    filename_excel = [ name '_N' num2str(1) '.xlsx'];
    writetable(Table,filename_excel,'Sheet', 3, 'Range','A5');
    
    cd current_dir;
    clear current_dir;