How to cancel the save program?

조회 수: 11 (최근 30일)
slumberk
slumberk 2011년 3월 5일
Hye guyz. I need some help here. I have this coding:
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
This coding have some problem. When i run this coding, it occurs this error:
??? 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 the cancel, then it will cancel the save program.

채택된 답변

Paulo Silva
Paulo Silva 2011년 3월 5일
Another way, might be better because the return function can have undesirable consequences.
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
else
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
end
  댓글 수: 2
slumberk
slumberk 2011년 3월 6일
how about if i want to cancel the inputdlg then it will do nothing and end the save program.
slumberk
slumberk 2011년 3월 6일
i think i already solve it by writing this code:
if isempty(fileName)
return
end
Thanks in advance

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Paulo Silva
Paulo Silva 2011년 3월 5일
if directoryName == 0 %# User pressed the "Cancel" button...
directoryName = ''; %# ...so choose the empty string for the folder
return
end

Walter Roberson
Walter Roberson 2011년 3월 5일
You should be checking that fileName is not empty, which would happen if the user does not enter anything in response to the inputdlg or cancels it.

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by