【发布时间】:2011-07-01 09:05:36
【问题描述】:
因为我是初学者,所以你们在这里真的帮助我使用 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文件夹中。我想让用户如何选择他想将 gui 保存在 .bmg 文件中的文件夹??
我将此编码用作@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
【问题讨论】:
-
发生错误是因为在下面的示例中,我在驼峰式中使用名称
fileName,而您使用全部小写的filename。
标签: user-interface matlab save