How to specific fig handle in function savefig

I first determine figHandles = findobj('Type', 'figure');
from open Matlab figures I saved earlier and get result
>> figHandles
figHandles = 4×1 Figure array:
Figure (3)
Figure (2)
Figure (1)
Figure (4)
I then tried multiple ways to specify handle in savefig, but get errorL
>> savefig('C:\Users\Owner\Documents\Research\TreasuryFunding\FiscalTheory\NetBondSalesNov12.fig', 'figHandles(1)','pdf')
Error using savefig (line 43)
H must be an array of handles to valid figures.
Then I tried but got same error.
savefig('C:\Users\Owner\Documents\Research\TreasuryFunding\FiscalTheory\NetBpndSalesNov12.fig', figHandles(1),'pdf')
Thank you

1 comentario

Steven Lord
Steven Lord el 10 de Dic. de 2021
Out of curiosity, was there something (a documentation page, a website, a similar function's behavior, etc.) that led you to believe that savefig would accept 'pdf' as the last input? If there is something and it's under MathWorks control I'd like to correct it to avoid misleading or confusing users in the future.

Iniciar sesión para comentar.

 Respuesta aceptada

Image Analyst
Image Analyst el 9 de Dic. de 2021

0 votos

Try exportgraphics() instead.

4 comentarios

It works, but figure is hidden by the legend. How to find instructions to edit?
I guess first I have to edit *.jpg file before using export graphics.
I'll google this
Thank you
Not sure why your legend is so enormous. You can change nearly everything in a graph. See the attached demo.
You can also make your figure bigger by maximizing it.
g = gcf;
g.WindowState = 'maximized'
This may make the legend a smaller proportion of the whole thing.
Here is matlab fig file, the original
Nancy Hammond
Nancy Hammond el 10 de Dic. de 2021
Thanks, Image Analyst. I sent in my proposal with shi*y graphics. The images I inserted into overleaf were horrible, blurred, illegible.
I'll try this and I have used g.WindowState = 'maximized'
I've tried exportgraphics, savefig. I have some new Matlab
plot recommendations.
Also going to eliminate legend and label curves with one or 2 letter text as I have seen colleagues do. And reached out to them to see what they do.
Hopefully I can edit the submission
Thanks for your help.

Iniciar sesión para comentar.

Más respuestas (1)

Voss
Voss el 9 de Dic. de 2021
The two- and three-input-argument options for calling savefig expect the figure to be the first input argument, so it would be:
savefig(figHandles(1),'C:\Users\Owner\Documents\Research\TreasuryFunding\FiscalTheory\NetBpndSalesNov12.fig')
Note that I removed the third argument 'pdf' because this is not a recognized option, according to the documentation. savefig will save the figure as a .fig file. If you want to save a figure as a .pdf file, you can use print:
print(figHandles(1),'C:\Users\Owner\Documents\Research\TreasuryFunding\FiscalTheory\NetBpndSalesNov12.pdf','pdf')

3 comentarios

Thank you, but these errors occurred. What's wrong here?
Thanks
savefig(figHandles(1),'C:\Users\Owner\Documents\Research\TreasuryFunding\FiscalTheory\NetBondSalesNov12.fig')
print(figHandles(1),'C:\Users\Owner\Documents\Research\TreasuryFunding\FiscalTheory\NetBondSalesNov12.pdf','pdf')
Error using inputcheck
Multiple inputs that look like file names:
'C:\Users\Owner\Documents\Research\TreasuryFunding\FiscalTheory\NetBondSalesNov12.pdf'
and 'pdf'.
Error in print (line 41)
[pj, devices, options ] = inputcheck( pj, inputargs{:} );
Oops. That last 'pdf' argument should've been '-dpdf'. That is:
print(figHandles(1),'C:\Users\Owner\Documents\Research\TreasuryFunding\FiscalTheory\NetBpndSalesNov12.pdf','-dpdf')
Nancy Hammond
Nancy Hammond el 10 de Dic. de 2021
Thanks, Ill try

Iniciar sesión para comentar.

Categorías

Más información sobre Printing and Saving en Centro de ayuda y File Exchange.

Preguntada:

el 9 de Dic. de 2021

Comentada:

el 10 de Dic. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by