How to fix error done by pressing "Cancel" button
조회 수: 21 (최근 30일)
이전 댓글 표시
Hi everybody!
I wrote a simple function to save my axes using saveas funct. but if I click on "Cancel" in the opened window, I have an error in my Matlab... There's a way to interrupt the operation of saving if users press "Cancel" without an error??
댓글 수: 0
채택된 답변
Titus Edelhofer
2012년 1월 18일
Hi,
the uiputfile dialog returns 0 for the filename if the user presses cancel:
filename = uiputfile;
if filename==0
% user pressed cancel
return
end
% go on with saving your data ...
Titus
댓글 수: 4
Ivan Demec
2023년 11월 28일
Your answer breaks the code if you use the multiselect option of the UIgetFile i.e.,
Undefined function 'eq' for input arguments of type 'cell'.
@Walter Roberson your solution works with multiselect. Thank you
Titus Edelhofer
2023년 11월 28일
Interesting coincidence: I wrote the answer a decade ago, and most often still use the filename==0 test. Believe it or not, just about 2 weeks ago I stumbled across my own solution not working (anymore) in case of multiselect :)
추가 답변 (2개)
Walter Roberson
2012년 1월 18일
Sorry, Cancel in which window exactly? And do you mean Cancel or do you mean the window close button? saveas() itself does not have a Cancel. If you are referring to something like a callback initiated from a window, have you considered setting the Cancel button to 'enable', 'off' during the time the saveas operation is going on?
댓글 수: 0
Jethro
2012년 1월 18일
댓글 수: 1
Walter Roberson
2012년 1월 18일
Yes, always test the output of uiputfile(), uigetfile(), uigetdir(), uiputdir()
참고 항목
카테고리
Help Center 및 File Exchange에서 Printing and Saving에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!