Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving a plot as a PNG in Matlab [duplicate]

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
like image 843
Xupla Avatar asked May 07 '12 07:05

Xupla


2 Answers

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.

like image 119
bruszzz Avatar answered Oct 30 '22 06:10

bruszzz


You can use print with the -dpng flag.

like image 31
H.Muster Avatar answered Oct 30 '22 06:10

H.Muster