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 vues (au cours des 30 derniers jours)
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

Réponse acceptée

Kelly Kearney
Kelly Kearney le 5 Déc 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)
  1 commentaire
Sean
Sean le 5 Déc 2013
Thank you so much!! I am still very much a novice and would have never thought of a switch/case block.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Dialog Boxes dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by