Cancel a program in MATLAB
I have this code:
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}); %# Sa开发者_开发技巧ve the file
set(gcf,'PaperPositionMode','auto');
end
It has some problem. When I run it, this error occurs:
??? Index exceeds matrix dimensions.
Error in ==> fyp_editor>uipushtool9_ClickedCallback at 1607
filePath = fullfile(directoryName,fileName{1}); %# Create the file path.
And another thing is when i pressed the cancel button, it kkeep going to filepath. How I want to do something like; when I push Cancel, then it will cancel the save program.
If the user presses Cancel fileName will be empty ( 0x0 cell array). fileName{1} is what causes the exception
精彩评论