【问题标题】:How to save the plotted figure automatically with source file name?如何使用源文件名自动保存绘制的图形?
【发布时间】:2019-12-14 23:59:54
【问题描述】:

我有一个包含数据的 matfile。我想绘制数据并以与 matfile 相同的文件名另存为图形。

clear all
%loading file
[file,path] = uigetfile
load(file);
% Plotting Processing
...
Plot(..,..)
hold off
legend show

现在我想将 jpg 文件保存为与加载的文件相同。这意味着存储在变量文件中的文件名。

但下面的代码只将 jpg 保存为 file.jpg。

%saving the figure
saveas(gcf,'file.jpg')

在代码开始时,我们需要选择文件以加载数据。该文件名将存储在变量文件中。 例如文件='test1.mat'

绘制数据后。我想将该图另存为 test1.jpg。代码必须自动完成。无论我选择什么 matfile,我都应该得到具有相同 matfile 名称的 jpg 输出。

【问题讨论】:

标签: matlab matlab-figure


【解决方案1】:

试试这个。使用“figure”调用来设置和获取图形的属性并绘制数据。

f=figure;    %%your data will go after this for plotting

用文件名保存图像。

saveas(f, [File_Name '_.png'])  %% for saving the figure in PNG

PS:File_Name 是文件名。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-06
    相关资源
    最近更新 更多