Saving a figure with multiple graphs
19 views (last 30 days)
Show older comments
Hi all, Assume that I have the following plot: fig = plot(t,xt, t, yt);
Now, if i want to save such a plot using saveas(fig,'ddddd.jpg'), I get into trouble. It seems to be because fig is now a 2x1 handle which probably saveas is not supporting ( I am not sure though). I have tried hgsave. But, the jpg file was not opening. Any comments?
0 Comments
Answers (1)
Matt Kindig
on 17 Apr 2013
saveas() takes a figure handle. The output of a plot() command is a line handle (or a 2x1 vector of line handles, as you have it). Instead, do this:
plot(t,xt, t, yt);
fig = gcf;
saveas(fig, 'dddddd.jpg');
This should work.
2 Comments
Matt Kindig
on 18 Apr 2013
Edited: Matt Kindig
on 18 Apr 2013
Payam, I think you are confused as to what 'fig' is. The handle 'fig' (which I have get set to the output of the gcf() function), is a handle to a figure, which doesn't have those properties at all.
Rather, you need to set the output of the plot() command (which outputs a line handle with properties such as 'lineWidth', 'MarkerSize', etc.) to a variable. Such as:
h = plot(t, xt, t, yt);
% h will be a 2x1 vector of LINE (not figure) handles
set(h(1), 'lineWidth', 2, 'MarkerSize, 5, ...); %set first line properties
set(h(2), 'lineWidth', 5, 'MarkerSize', 10, ...); %set second line properties
%you can also set a bunch of line handles to the same properties, using:
set(h,'lineWidth', 3, 'MarkerSize', 8, ....);
See Also
Categories
Find more on Printing and Saving in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!