User interface 在MATLAB中取消一个程序
我有以下代码:User interface 在MATLAB中取消一个程序,user-interface,matlab,save,User Interface,Matlab,Save,我有以下代码: 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
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
它有一些问题。运行时,会出现以下错误:
???索引超过了矩阵维度
==>fyp\u编辑器>uipushtool9\u单击1607处的回调时出错filePath=fullfile(目录名,文件名{1});%#创建文件路径
另一件事是当我按下取消按钮时,它会继续进入文件路径。我是多么想做这样的事情;当我按下Cancel时,它将取消保存程序。如果用户按下Cancel,文件名将为空(0x0单元格数组)。fileName{1}是导致异常的原因运行“fileName=inputdlg('请输入您的图形名称')”,并查看在对话框窗口中按“取消”时fileName发生了什么。