Saving a plot as a PNG in Matlab [duplicate]

2019-03-13 11:56发布

This question already has an answer here:

I have a function that is plotting a time series, now I want to save this as an image how can this be done please?

function TimeSeriesImages(a, b, c, d, e, f, g, h, i, j, k, l)
x = [a b c d e f g h i j k l];
ts1 = timeseries(x,1:12);
ts1.Name = 'Monthly Count';
ts1.TimeInfo.Units = 'months';
ts1.TimeInfo.Format = 'mmm dd, yy'
ts1.Time=ts1.Time-ts1.Time(1);
plot(ts1)
end

2条回答
放荡不羁爱自由
2楼-- · 2019-03-13 12:41

Another way of saving figures in Matlab is handle them with variables and saving them later.

For example:

a=bar(...);
b=hist(...);   %some figures
c=plot(...);

saveas(a, 'path\to\file\abc1.png','png');
saveas(b, 'path\to\file\abc2.png','png');
saveas(c, 'path\to\file\abc3.png','png');

Fragment from the official Matlab help:

saveas - Save figure or Simulink block diagram using specified format

Syntax

saveas(h,'filename.ext') 
saveas(h,'filename','format')

Description

saveas(h,'filename.ext') saves the figure or Simulink block diagram with the handle h to the file filename.ext. The format of the file is determined by the extension, ext. See Matlab help for more.

查看更多
\"骚年 ilove
3楼-- · 2019-03-13 12:50

You can use print with the -dpng flag.

查看更多
登录 后发表回答