How do I index correctly from my questdlg command to my if statement? I am trying to direct the user into different code based on their questdlg responses. I have many more in this code but I am stuck HELP!

8 次查看(过去 30 天)
quest = 'What type of rod are you using?';
qtitle = 'Axial load problem';
a = {'Circular', 'Rectangular'};
resp=questdlg(quest,qtitle,a{1},a{2},a{1});
h=msgbox(sprintf('You selected %s',resp));
respa = str2num('resp');
waitfor(h);
if respa == 1
% create a user prompted space to calculate the axial load problem for a
% circular rod
dlg_prompts = {'Axial load','Radius','Inner Radius',...
'Length','Young''s Modulus E'};
dlg_title = 'Axial Load';
dlg_defaults = {'0','0','0','0','0'};
opts.Resize = 'on'; % a structure
dlg_ans = inputdlg(dlg_prompts,dlg_title,1,dlg_defaults,opts);
P = str2double(dlg_ans(1));
r = str2double(dlg_ans(2));
ir = str2double(dlg_ans(3));
L = str2double(dlg_ans(4));
E = str2double(dlg_ans(5));
else
% create a user prompted space to calculate the axial load problem for a
% rectangular rod
dlg_prompts = {'Axial load','Base','Height','Inner Base','Inner Height',...
'Length','Young''s Modulus E'};
dlg_title = 'Axial Load';
dlg_defaults = {'0','0','0','0','0','0','0'};
opts.Resize = 'on'; % a structure
dlg_ans = inputdlg(dlg_prompts,dlg_title,1,dlg_defaults,opts);
P = str2double(dlg_ans(1));
b = str2double(dlg_ans(2));
h = str2double(dlg_ans(3));
ib = str2double(dlg_ans(4));
ih = str2double(dlg_ans(5));
L = str2double(dlg_ans(6));
E = str2double(dlg_ans(7));
end%if

采纳的回答

Kelly Kearney
Kelly Kearney 2013-12-5
Since you know the possible strings in advance, a switch/case block might be better:
quest = 'What type of rod are you using?';
qtitle = 'Axial load problem';
a = {'Circular', 'Rectangular'};
resp=questdlg(quest,qtitle,a{1},a{2},a{1});
switch resp
case 'Circular'
% circular code here
case 'Rectangular'
% rect code here
end
Or if you must number it...
[tf, respa] = ismember(resp, a)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Dialog Boxes 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by