How to specific fig handle in function savefig
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Steven Lord
2021-12-10
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.
采纳的回答
更多回答(1 个)
Voss
2021-12-9
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 个评论
Voss
2021-12-9
Oops. That last 'pdf' argument should've been '-dpdf'. That is:
print(figHandles(1),'C:\Users\Owner\Documents\Research\TreasuryFunding\FiscalTheory\NetBpndSalesNov12.pdf','-dpdf')
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Printing and Saving 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!