Saving the plot: saveas does not seem to work

9 ビュー (過去 30 日間)
alpedhuez
alpedhuez 2017 年 12 月 28 日
コメント済み: alpedhuez 2017 年 12 月 29 日
I have the following code and I try to save the plot with "saveas" but it does not seem to work. Please advise.
x0=10;
y0=10;
width=375;
height=210;
set(gcf,'units','points','position',[x0,y0,width,height])
set(gca,'box','on')
% Remove tick marks from the plot
set(gca, 'TickLength', [0 0]);
plot(****, ****)
hold on
plot(****, ****)
hold on
plot(****, ****)
hold on
plot(****, ****)
% Place legend under the plot, centered
legend('****','****','****','****','Location', 'southoutside','Orientation','horizontal')
thandle = title({'****'});
yhandle=ylabel('****');
saveas(gca,'C:/****.png');
  3 件のコメント
alpedhuez
alpedhuez 2017 年 12 月 28 日
編集済み: alpedhuez 2017 年 12 月 28 日
Error using name (line 102) Cannot create output file 'C:\filename.png'.
Error in print (line 71) pj = name( pj );
Error in saveas (line 168) print( h, name, ['-d' dev{i}] )
Error in filename (line 222) saveas(gca,'C:\filename.png');
alpedhuez
alpedhuez 2017 年 12 月 29 日
C:\Dropbox\ worked.

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 12 月 29 日
saveas(gca,'C:\filename.png');
tries to write into the top level directory of the C: drive. MS Windows does not permit users to write into that directory (not unless an administrator goes in and modifies the permissions for that directory.)
If you want to save into the "current" directory, leave out the 'C:\' , giving the file name as just 'filename.png' . If you want to save into the "current" directory of the C: drive, then leave out the \, giving the file name as just 'C:filename.png' (Note: MS Windows keeps a different "current" directory for each drive.)
  3 件のコメント
Walter Roberson
Walter Roberson 2017 年 12 月 29 日
If you do not need to know what the current directory is for a particular drive, then just give either of the commands
cd
or
pwd
If you need to know the current directory on a particular drive then
!cd C:
or
system('cd C:')
alpedhuez
alpedhuez 2017 年 12 月 29 日
C:\Dropbox worked.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

タグ

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by