creating a warning dialog that wait until the user press ok, if the user press x the execution stops
54 次查看(过去 30 天)
显示 更早的评论
Im writing a code that creates xlsx file (using writetable function)
I want that if thier is a xlsx file with the same name a warning alert will pop and tell the user: their are files with the same name, are you sure you want to override them? If the user press ok -> the execution of the code continues. If the user press X (get out from the warning dialog window) the execition of the code stops.
I tried to use uialert and uiwait as the following example: https://www.mathworks.com/help/matlab/ref/uiwait.html?searchHighlight=uiwait&s_tid=srchtitle_uiwait_1
in the title : "Wait for Button Press" they say that the following code should work:
f = figure('Position',[500 500 400 300]);
c = uicontrol('String','Continue','Callback','uiresume(f)');
uiwait(f)
disp('Program execution has resumed');
But it does not work. The uiwait, wait untii the user close the figure and not until the user press OK.
I want to do the following:
- user press OK -> execution continues
- user get out from the warning dialog window -> execution stops
It sounds very simple to me, but somehow I don't succeed to do it,
Someone did something similar?
0 个评论
采纳的回答
Simon Chan
2023-5-14
fig = uifigure;
selection = uiconfirm(fig,'Overwrite existing excel file','File Operation');
switch selection
case 'OK'
disp('Code to write data into excel file');
case 'Cancel'
return
end
close(fig);
更多回答(1 个)
Jon
2023-5-11
Does the behavior demonstrated in my example below do what you want?
for k = 1:10
if k ==3 % condition simulating duplicate file found, just for example
% Display confirmation for file overwrite
selection = questdlg('Overwrite duplicate file?','Duplicate File',...
'Overwrite','Exit','Exit');
if strcmp(selection,'Exit')
break
end
end
% display iteration (just to show something is happening
disp(k)
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!