How do I save a Figure with a Filename based on it's contents?
3 次查看(过去 30 天)
显示 更早的评论
I've written some code to extract data from an excel spreadsheet into a .mat file for further processing. For each .mat file, I want to produce a corresponding figure showing the data that it contains.
I've managed to automatically name the .mat file using the start and end dates of the data that it contains, and I want to name the figure in the same way. However I get an error message when I use the following code:
FileName = ["DMFlowData", StartDate, EndDate]
Filename = strjoin(FileName)
print (fig, FileName,'-fillpage','-dpdf')
'The messages that I get are:
'Error in checkArgsForHandleToPrint'
Handle input argument contains nonhandle values.
Adding ' ' either side of my variable FileName just results in a figure saved as FileName.pdf, not the dates. I've omitted the code used to create the figure.
Thanks!
0 个评论
回答(1 个)
Steven Lord
2020-1-8
What does the variable named fig contain? I think you intend for it to be the fig input argument listed in the Description section of the print documentation page, but it contains a handle to something that's not a figure object or Simulink block diagram.
Maybe it's an axes handle, in which case you should instead print the figure that contains it? So in the example below you'd print using f (the figure) rather than ax (the axes.)
ax = axes
f = ancestor(ax, 'figure')
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!