gpt4 book ai didi

matlab - 在 MatLab 中使用当前文件名保存图形

转载 作者:太空宇宙 更新时间:2023-11-03 20:35:05 25 4
gpt4 key购买 nike

我有一个脚本,它一次从我当前的工作目录中提取一个文件并绘制指定的信息。我想将每个图保存为 jpeg(tiff 也可以),并使用它正在绘制的文件的名称。我有大约 3000 个文件,所以我正在寻找一种自动执行此操作的方法。

我认为如果将其放在 for 循环的末尾可能会起作用:

saveas(gcf, '   ',jpg)

我不确定要为文件名加上引号。

例子

data1.mat 中的数据图应保存在文件 data1.jpeg

最佳答案

如果 loadedFileName 是您刚刚加载的文件的名称(也许是路径),那么您可以执行类似以下的操作以使用相同的文件名保存 jpeg

% get the path, name and extension of the file just loaded
[path, name, ext] = fileparts(loadedFileName);

% grab what you want to create the filename of the jpeg to save
jpegToSaveFileName = [name '.jpg']; % use path if you want to save to same directory

% save the figure as a jpeg
saveas(gcf,jpegToSaveFileName,'jpg');

试试上面的方法,看看会发生什么。如果您需要向文件名添加路径,则执行类似

jpegToSaveFileName = fullfile(path, jpegToSaveFileName);

试试上面的方法,看看它是否满足您的需要!

关于matlab - 在 MatLab 中使用当前文件名保存图形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24046157/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com