Matlab and Unix server - path issues when trying to create and save to folder from Matlab
2 ビュー (過去 30 日間)
古いコメントを表示
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
0 件のコメント
採用された回答
Fangjun Jiang
2011 年 5 月 17 日
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;
その他の回答 (2 件)
Jan
2011 年 5 月 17 日
Use the file separators matching to your OS:
graph_path_fig = fullfile('graphs', 'fig');
graph_path_pdf = fullfile('graphs', 'pdf');
If you cannot mmodify the functions, which create the file names, you can fix them afterwards:
function PathName = FixPath(PathName)
if ispc
PathName = strrep(PathName, '/', '\');
else
PathName = strrep(PathName, '\', '/');
end
Most system functions should work with both file separators - but obvioulsy there is still the one or other incompatibility. See also: FEX: GetFullPath
BTW: If Matlab's MLint tells you that the additional square brackets are not needed, remove them - they waste time and reduce readability.
2 件のコメント
Walter Roberson
2011 年 5 月 17 日
Windows works with \ and / but Unix type systems only work with / and using \ often leads to parsing problems if the command gets interpreted at the Unix shell level. Thus if you had to choose just one of them as a path delimiter, choose / as the delimiter.
Jason Ross
2011 年 5 月 17 日
Can you create a file in graphs\fig\fig_practice outside of MATLAB?
Do you get any errors when you run your code?
If you run this in the debugger, what are the values of save_fig and save_pdf before you get to the saveas lines?
参考
カテゴリ
Help Center および File Exchange で File Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!