Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 其它 > 资料存档
资料存档 资料存档
回复
 
主题工具 显示模式
旧 2019-12-14, 20:13   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,008
声望力: 66
poster 正向着好的方向发展
帖子 用户如何将GUI(结果)保存在其他文件夹中?

因为我是初学者,所以在座的各位真的可以帮助我使用matlab。现在我对Matlab中的gui有所了解。我有个问题。我有一个图形用户界面和一个保存按钮。我做了这个编码:

filename = inputdlg('Please enter the name for your figures'); extensions = {'fig','bmp'}; for k = 1:length(extensions saveas(gcf, filename{:}, extensions{k}) set(gcf,'PaperPositionMode','auto') end 但这只能保存在我的GUI文件夹中。我要如何使用户可以选择他要在.bmg文件中保存gui的文件夹?

我将此编码用作@gnovice建议的编辑内容:

filename = inputdlg('Please enter the name for your figures'); extensions = {'fig','bmp'}; directoryName = uigetdir; %# Open directory-selection dialog if directoryName == 0 %# User pressed the "Cancel" button... directoryName = ''; %# ...so choose the empty string for the folder end saveas(gcf,fullfile(directoryName,fileName),extension); %# Save to the folder set(gcf,'PaperPositionMode','auto') 但是发生了此错误:

??? Error while evaluating uipushtool ClickedCallback ??? Undefined function or variable 'fileName'. Error in ==> fyp_editor>uipushtool9_ClickedCallback at 1605 saveas(gcf,fullfile(directoryName,fileName),extension); %# Save to the folder Error in ==> gui_mainfcn at 96 feval(varargin{:}); Error in ==> fyp_editor at 42 gui_mainfcn(gui_State, varargin{:}); Error in ==> @(hObject,eventdata)fyp_editor('uipushtool9_ClickedCallback',hObject,eventdata,guidata(hObject)) ??? Error while evaluating uipushtool ClickedCallback

回答:

您显然已经知道了INPUTDLG对话框(因为您在上面使用了它),所以令您感到惊讶的是您还没有遇到UIGETDIR对话框(或与此相关的任何其他对话框)。您可以使用它来让用户浏览并选择一个文件夹,如下所示:

fileName = inputdlg('Please enter the name for your figures'); directoryName = uigetdir('','Please select a folder to save to'); if directoryName == 0 %# User pressed the "Cancel" button... directoryName = ''; %# ...so choose the empty string for the folder end filePath = fullfile(directoryName,fileName{1}); %# Create the file path extensions = {'fig','bmp'}; for k = 1:length(extensions) saveas(gcf,filePath,extensions{k}); %# Save the file set(gcf,'PaperPositionMode','auto'); end 请注意,我使用函数FULLFILE构造文件路径,该路径会自动处理给定平台所需的文件分隔符



更多&回答...
poster 当前离线   回复时引用此帖
回复

主题工具
显示模式

发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛禁用 表情符号
论坛启用 [IMG] 代码
论坛启用 HTML 代码



所有时间均为北京时间。现在的时间是 03:20


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.