Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
User interface 在MATLAB中取消一个程序_User Interface_Matlab_Save - Fatal编程技术网

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发生了什么。