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 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Kelly Kearney
Kelly Kearney am 5 Dez. 2013
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)

Weitere Antworten (0)

Kategorien

Mehr zu Dialog Boxes finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by