【发布时间】:2014-06-17 18:00:58
【问题描述】:
我在自动保存 GUI 轴面板中绘制的图形时遇到了一些问题。这是我到目前为止的代码:
x= [1 2 3 4 5 6 7 8 9 10];
y = [10 5 6 7 8 20 5 4 3 8];
p = polyfit(x, y, 6);
r = polyval(p, x);
xlabel(handles.axes1, 'Time (\mus)');
ylabel(handles.axes1, 'Angular Velocity (rad/s)');
title(handles.axes1, 'Angular Velocity vs. Time (kT Test)');
aV = plot(handles.axes1, x, y, x, r, 'g--');
%Save figure
ftmp = figure();
copyobj(handles.axes1, ftmp);
set(ftmp, 'units', 'normalized', 'outerposition', [0 0 1 1]);
%Create file name
fileName = ['Test' num2str(time(1)) '_' num2str(time(2)) '_' num2str(time(3))]
saveas(ftmp, fileName, 'png');
图像会自动保存,但显示不正确。例如,保存的图像如下所示:
如您所见,图像非常倾斜。但是,如果我手动保存图像,则整个图形将居中并保存。有没有办法在自动保存的同时重新定位图形?
(请注意,我正在寻找不使用export_fig 的解决方案。
我已经搜索了一段时间,类似问题的答案都没有为我的问题提供解决方案。
感谢任何建设性的建议。
【问题讨论】:
-
您是否有理由要以这种方式创建图形? (即使用copyobj等)?如果您只想要一个图形并保存为 png,则有更简单的方法。
-
我没有特别需要这样做。我使用 copyobj 的唯一原因是因为这就是我在本网站和 mathworks 上的多个答案中看到它的方式。如果有更好的方法,我愿意尝试。
标签: matlab matlab-figure