How to read user input of multiple string separately in inputdlg
Show older comments
I want to enter user input using inputdlg,
if true
% prompt = {'Input the number of Criteria','Input short name of criteria'};
dlg_title = 'Alternative Evauation';
num_lines = 1;
defaultans = {'3','{Criteria1,Criteria2,Criteria3}'};
answer = inputdlg(prompt,dlg_title,num_lines,defaultans);
end
although I am able to read 'number of Criteria' as
n=str2num(answer{1})
but when I try to read the read the short name of criteria
as
str=answer{2}
then instead of reading str as 'Criteria1', 'Criteria2', 'Criteria3'separately, it reads as Criteria1Criteria2Criteria3,
Please tell me how can I handle the multiple string input separately.
Thanks
Accepted Answer
More Answers (1)
Star Strider
on 22 Apr 2017
Try this instead:
prompt = {'Input the number of Criteria','Input short name of Criterion 1','Input short name of Criterion 2','Input short name of Criterion 3'};
dlg_title = 'Alternative Evauation';
num_lines = [1 20];
defaultans = {'3','Criterion 1','Criterion 2','Criterion 3'};
answer = inputdlg(prompt,dlg_title,num_lines,defaultans);
2 Comments
Sanjeev Goyal
on 22 Apr 2017
Star Strider
on 22 Apr 2017
My pleasure.
You will have to experiment on your own to get the inputdlg function to do what you want, if you want it to be adaptable. One way would be to set up the maximum number of criteria you believe would ever be needed, and test for the response being different from the default. Or ask first in another inputdlg for the number the user will provide, then dynamically design the second inputdlg to accommodate that number.
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!