Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
printing to PDF

Subject: printing to PDF

From: Misha Koshelev

Date: 27 May, 2009 01:32:01

Message: 1 of 4

Hi, thank you very much for all your help.

I would like to print a matlab plot to PDF programatically. I am using the print command, but would like:
(i) the PDF to only contain the plot and have no margins
(ii) to not even show a plot window at all when plotting/printing
and
(iii) ideally to not have to install any extra .m files

Any options to do this?

Thank you
Misha

Subject: printing to PDF

From: Doug Schwarz

Date: 27 May, 2009 02:51:32

Message: 2 of 4

In article <gvi56h$h0$1@fred.mathworks.com>,
 "Misha Koshelev" <mk144210@bcm.edu> wrote:

> Hi, thank you very much for all your help.
>
> I would like to print a matlab plot to PDF programatically. I am using the
> print command, but would like:
> (i) the PDF to only contain the plot and have no margins
> (ii) to not even show a plot window at all when plotting/printing
> and
> (iii) ideally to not have to install any extra .m files
>
> Any options to do this?
>
> Thank you
> Misha


Something like this?

  fig = figure('Visible','off',...
      'PaperPosition',[0 0 6 4],...
      'PaperSize',[6 4])
  plot(rand(5))
  set(gca,'Position',[0 0 1 1])
  print(fig,'-dpdf','test.pdf')

--
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.

Subject: printing to PDF

From: Misha Koshelev

Date: 27 May, 2009 13:04:02

Message: 3 of 4

Doug Schwarz <see@sig.for.address.edu> wrote in message <see-A0578A.22513226052009@news.frontiernet.net>...
> In article <gvi56h$h0$1@fred.mathworks.com>,
> "Misha Koshelev" <mk144210@bcm.edu> wrote:
>
> > Hi, thank you very much for all your help.
> >
> > I would like to print a matlab plot to PDF programatically. I am using the
> > print command, but would like:
> > (i) the PDF to only contain the plot and have no margins
> > (ii) to not even show a plot window at all when plotting/printing
> > and
> > (iii) ideally to not have to install any extra .m files
> >
> > Any options to do this?
> >
> > Thank you
> > Misha
>
>
> Something like this?
>
> fig = figure('Visible','off',...
> 'PaperPosition',[0 0 6 4],...
> 'PaperSize',[6 4])
> plot(rand(5))
> set(gca,'Position',[0 0 1 1])
> print(fig,'-dpdf','test.pdf')
>
> --
> Doug Schwarz
> dmschwarz&ieee,org
> Make obvious changes to get real email address.

Thank you, that is perfect!

Btw, if I want to have more than one plot do I just do:
plot(...)
hold on;
plot(...)
hold off;

Or is there a more elegant way to do this?

Thank you
Misha

Subject: printing to PDF

From: Doug Schwarz

Date: 27 May, 2009 13:11:05

Message: 4 of 4

In article <gvjdo2$28m$1@fred.mathworks.com>,
 "Misha Koshelev" <mk144210@bcm.edu> wrote:

> Doug Schwarz <see@sig.for.address.edu> wrote in message
> <see-A0578A.22513226052009@news.frontiernet.net>...
> > In article <gvi56h$h0$1@fred.mathworks.com>,
> > "Misha Koshelev" <mk144210@bcm.edu> wrote:
> >
> > > Hi, thank you very much for all your help.
> > >
> > > I would like to print a matlab plot to PDF programatically. I am using
> > > the
> > > print command, but would like:
> > > (i) the PDF to only contain the plot and have no margins
> > > (ii) to not even show a plot window at all when plotting/printing
> > > and
> > > (iii) ideally to not have to install any extra .m files
> > >
> > > Any options to do this?
> > >
> > > Thank you
> > > Misha
> >
> >
> > Something like this?
> >
> > fig = figure('Visible','off',...
> > 'PaperPosition',[0 0 6 4],...
> > 'PaperSize',[6 4])
> > plot(rand(5))
> > set(gca,'Position',[0 0 1 1])
> > print(fig,'-dpdf','test.pdf')
> >
> > --
> > Doug Schwarz
> > dmschwarz&ieee,org
> > Make obvious changes to get real email address.
>
> Thank you, that is perfect!
>
> Btw, if I want to have more than one plot do I just do:
> plot(...)
> hold on;
> plot(...)
> hold off;
>
> Or is there a more elegant way to do this?
>
> Thank you
> Misha

You can do it that way, though you might want to specify the color for
each plot so each curve doesn't get the same color. Or you can use a
single plot command:

  plot(x1,y1,x2,y2)

and both of the curves (in this example) will plot with a different
color automatically.

--
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us