From: Helen on
This has to be something people do every day, and yet the documentation does not describe it correctly.

I want to save a figure to file with a variable file name (composed from a data group and a number). The following doesn't work because matlab reads 'filename' as a literal not a variable.

print '-pdf' filename

The documentation says to use the functional form and gives the following as an example:

print('-dpdf', filename)

Using this generates the matlab error

"??? Error using ==> print at 325
Handle input argument contains non-handle value(s).

Error in ==> printtest at 103
print('-dpdf', filename)"

Adding the handle reference 'gcf' (with or without quotes) gets the same error.
From: Rune Allnor on
On 6 Feb, 16:54, "Helen " <helenfrom...(a)gmail.com> wrote:
> This has to be something people do every day, and yet the documentation does not describe it correctly.  
>
> I want to save a figure to file with a variable file name (composed from a data group and a number).   The following doesn't work because matlab reads 'filename' as a literal not a variable.
>
> print '-pdf' filename
>
> The documentation says to use the functional form and gives the following as an example:
>
> print('-dpdf', filename)

This one works in R2006a:

plot(rand(10))
fname = 'test.pdf';
print(fname,'-dpdf')

If the example you state is verbatim from the docs, the
docs are flawed.

Rune
From: ImageAnalyst on
If you don't have a current graphics figure then it thinks that what
follows the dash is the handle to the figure. In other words I guess
it thinks dpdf is the name of a handle to a figure. But it's not, so
it bombs. What does it say in the command window when you say
whos gfc
From: Helen on
Hi Rune, and thanks for your reply.

I tried your suggestion but it didn't work. I am running 2009b which, to be honest, sucks badly compared to earlier versions. Here's a quote from the documentation:

"This example combines the previous two examples and uses the function form to print using both a handle variable and a file name variable:

h = figure; plot(1:4,5:8)
filename = 'mydata';
print(h, '-dpsc', filename)

This example works ONLY if you assign filename the literal value 'x'. If you try to assign it a text variable, the command fails with a reference to the handle.

I've also been disappointed with changes to plotting functions such as bar plots, which used to be fast and simple to get nice results just using the defaults. Text concatenation doesn't seem to work the way it used to. Documentation is badly written and unclear. My "outsource" detector is firing.

Rune Allnor <allnor(a)tele.ntnu.no> wrote in message <51336523-3117-426c-9711-49b3dc801e3a(a)s12g2000yqj.googlegroups.com>...
> On 6 Feb, 16:54, "Helen " <helenfrom...(a)gmail.com> wrote:
> > This has to be something people do every day, and yet the documentation does not describe it correctly.  
> >
> > I want to save a figure to file with a variable file name (composed from a data group and a number).   The following doesn't work because matlab reads 'filename' as a literal not a variable.
> >
> > print '-pdf' filename
> >
> > The documentation says to use the functional form and gives the following as an example:
> >
> > print('-dpdf', filename)
>
> This one works in R2006a:
>
> plot(rand(10))
> fname = 'test.pdf';
> print(fname,'-dpdf')
>
> If the example you state is verbatim from the docs, the
> docs are flawed.
>
> Rune
From: Rune Allnor on
On 6 Feb, 17:56, "Helen " <helenfrom...(a)gmail.com> wrote:
> Hi Rune, and thanks for your reply.
>
> I tried your suggestion but it didn't work.   I am running 2009b which, to be honest, sucks badly compared to earlier versions.   Here's a quote from the documentation:  
>
> "This example combines the previous two examples and uses the function form to print using both a handle variable and a file name variable:
>
> h = figure; plot(1:4,5:8)
> filename = 'mydata';
> print(h, '-dpsc', filename)
>
> This example works ONLY if you assign filename the literal value 'x'.   If you try to assign it a text variable, the command fails with a reference to the handle.  

I'm not sure I undesrand: Matlab saves the file under tha *name*,
not the contents, of the variable?

Weird.

This one works under 2006a:

h = figure;
plot(1:4,5:8)
filename = sprintf('f%04d-%02d.pdf',1,2);
print(h, '-dpdf', filename)

Rune