MATLAB: Matlab and Unix server – path issues when trying to create and save to folder from Matlab

unix saveas graph folder path

Hi, I am running Matlab on a remote Unix server. I am new to Unix, so something with the file structure is not meshing with my Matlab code. I first run my Matlab code on my windows machine, and everything works great. However, I run into problems on the Unix server. For example,
graph_path_fig = ['graphs\fig\'];
graph_path_pdf = ['graphs\pdf\'];
if exist([graph_path_fig],'file')
rmdir([graph_path_fig],'s')
else
end
if exist([graph_path_pdf],'file')
rmdir([graph_path_pdf],'s')
else
end
mkdir(graph_path_fig)
mkdir(graph_path_pdf)
Then, I form a graph and try to save it as a .pdf and a .fig. The .pdf saves to the correct folder, while the .fig does not.
fh = figure(1);
hold all
h1 = plot(grid_num,grid_num_sq);
set(h1,'LineStyle','-','LineWidth',2.0,'Color','Blue')
hold off
filename = ['fig_practice'];
save_fig = [graph_path_fig,filename];
save_pdf = [graph_path_pdf,filename];
saveas(fh,save_fig,'fig')
saveas(fh,save_pdf,'pdf')
The .pdf saves to the correct file. The .fig does not. It saves in the directory of the mfile that I am running with the following name: graphs%5Cfig%5Cfig_practice
This is instead of the correct filepath of graphs\fig\fig_practice. Any help about how to circumvent this problem would be greatly appreciated.
All the best, Bob

Best Answer

My guess is that it is due to the difference of the file seperator for Windows (\) and Unix (/). But why it works for .pdf file but not for .fig file?
help filesep;
help pathsep;
help fullfile;