【问题标题】:Possible to save figures into variables instead of files in Matlab?可以将数字保存到变量而不是 Matlab 中的文件中吗?
【发布时间】:2018-02-01 21:19:09
【问题描述】:

我有 Matlab 代码,例如:

f=figure(1)
plot(x,y)
hold on
plot(x1,y1)
hold on
...
plot(xf, yf)
%want to save this into a VARIABLE, NOT into a .fig, .png, jpg, or other kind of file

因此,如果可以将其保存到某个变量 var_fig 中,我想稍后打开该图(例如在具有多个已保存图/图的子图中)执行类似的操作

showfig(var_fig)

这在 Matlab 中可行吗?

【问题讨论】:

  • 解决“保存图形数据”问题的另一种方法是将原始数据存储在一个文件中,并在“绘图图形”脚本的开头加载它。在这种情况下,您只需使用上述保存命令将x,y,x1,y1,xf,yf 存储在 *.mat 文件中,然后在执行图形脚本之前加载数据。

标签: matlab plot matlab-figure


【解决方案1】:

这是可能的,但不推荐。您可以使用save 保存任何变量:

myfigure = gcf; %store current figure in a variable
save('filename','myfigure');

但是根据 Matlab 警告:

Warning: Figure is saved in filename.mat. Saving graphics handle variables
can cause the creation of very large files. To save graphics figures,
use savefig. 

这里是savefig的使用方法

【讨论】:

    猜你喜欢
    • 2021-04-15
    • 2023-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-26
    • 2018-04-16
    • 2014-09-13
    相关资源
    最近更新 更多