【问题标题】:An invalid handle error when using hgexport and saveas in Matlab在 Matlab 中使用 hgexport 和 saveas 时出现无效句柄错误
【发布时间】:2014-02-03 15:52:43
【问题描述】:

我正在尝试在 Matlab 中编写一个代码,该代码将生成一个图形,然后将图形保存或导出到我的目录中。我使用的代码如下:

h = figure('name','HousingIndex');
plot(quarter,indexSample,quarter,indexSubsample);
legend('Index Sample','Index Repeat Subsample');
title('Housing Index');
xlabel('Quarter');
ylabel('Index');

其中“季度”是 1×75 的连续季度向量,“indexSample”和“indexSubsample”是 1×75 的索引值向量。但是,当我尝试使用 hgexport 函数导出图形时:

hgexport(h,'HousingIndex.jpg');

我收到以下错误消息:

??? Error using ==> hgexport at 140
First argument must be a handle to a figure.

我也尝试过使用 saveas 函数:

saveas(h,'HousingIndex.jpg')

我收到以下错误消息:

??? Error using ==> saveas at 59
Invalid handle.

这两个错误都表明我的句柄无效。我将非常感谢一个关于为什么我得到一个无效句柄的描述性答案以及这个问题的解决方案。

【问题讨论】:

  • 哪个版本的 Matlab?

标签: matlab save export figure save-as


【解决方案1】:

遇到了同样的问题,但找到了解决方法:

figure
h = plot([1:5],[1:5])
print('testing', '-dpng')

第一个设置一个新的空图(也许可以不用这一步,但它对我有用),最后一个创建一个 png 文件(因此 -dpng ) 名称为“测试”,情节在 h 中,瞧!它有效:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-27
    • 1970-01-01
    • 2018-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多