필터 지우기
필터 지우기

Saving a figure with multiple graphs

조회 수: 19 (최근 30일)
Payam
Payam 2013년 4월 17일
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?

답변 (1개)

Matt Kindig
Matt Kindig 2013년 4월 17일
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
Payam
Payam 2013년 4월 17일
It worked very well. Thanks! The way you approached the problem makes an absolute sense. However, the problem is when you assign fig to gcf, then you are not able to change the properties such as 'lineWidth' etc using set(fig,'lineWidth',2,'MarkerSize',...) as it is not clear which handle you are referring to. Can I ask for your inputs on that? Thanks again.
Matt Kindig
Matt Kindig 2013년 4월 18일
편집: Matt Kindig 2013년 4월 18일
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, ....);

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by