簡體   English   中英

如何在inputdlg()中捕獲用戶

[英]How can I trap the user in inputdlg()

這是我的計划。

clc
clear
ques='Yes';
while strcmp(ques,'Yes')
ns={'One','Two','Three','Four','Five'};
[selection ok]= listdlg('liststring',ns,'selectionmode','single');
while ok ==0
    msgbox('Please make a selection')
    [selection ok]= listdlg('liststring',ns,'selectionmode','single');
end
gradebook = {};
for d=1:selection
sinfo ={'Enter student name','Numerical grade for 1st exam (out of 100):','Numerical grade for 2nd exam (out of 100):','Numerical grade for 3rd exam (out of 100):'};
info=inputdlg(sinfo);
gradebook= [gradebook info];
end
for d=1:selection
    average(d)=mean(str2double(gradebook(2:end,d)));
end
[value where]=max(average);
name=gradebook {1,where};
msg=sprintf('%s has the highest average. Average grade is %.2f%%',name,value);
ok2=msgbox(msg);
waitfor(ok2)
ques=questdlg ('Do you want to repeat the program?');
end

我的問題是如果用戶按“取消”而不是“確定”,我如何重新顯示inputdlg()?

非常感謝你! :)

您應該讓用戶有機會在任何步驟取消該程序。 可能會詢問他/她是否真的要取消並可能丟失輸入的數據。

無論如何這里是你如何做到的:

info = {};
while isempty(info)
    info=inputdlg(sinfo);
end

此外,您不需要兩個listdlg語句:

ok = 0;
while ok == 0
    [selection ok] = listdlg('liststring',ns,'selectionmode','single');
end

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM