MATLAB: How to read user input of multiple string separately in inputdlg

inputMATLABstring

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

Best Answer

Here's a snippet I post regularly:
% Ask user for two floating point numbers.
defaultValue = {'45.67', '78.91'};
titleBar = 'Enter a value';
userPrompt = {'Enter floating point number 1 : ', 'Enter floating point number 2: '};
caUserInput = inputdlg(userPrompt, titleBar, 1, defaultValue);
if isempty(caUserInput),return,end; % Bail out if they clicked Cancel.
% Convert to floating point from string.
usersValue1 = str2double(caUserInput{1})
usersValue2 = str2double(caUserInput{2})
% Check usersValue1 for validity.
if isnan(usersValue1)
% They didn't enter a number.

% They clicked Cancel, or entered a character, symbols, or something else not allowed.

% Convert the default from a string and stick that into usersValue1.
usersValue1 = str2double(defaultValue{1});
message = sprintf('I said it had to be a number.\nTry replacing the user.\nI will use %.2f and continue.', usersValue1);
uiwait(warndlg(message));
end
% Do the same for usersValue2
% Check usersValue2 for validity.
if isnan(usersValue2)
% They didn't enter a number.
% They clicked Cancel, or entered a character, symbols, or something else not allowed.
% Convert the default from a string and stick that into usersValue2.
usersValue2 = str2double(defaultValue{2});
message = sprintf('I said it had to be a number.\nTry replacing the user.\nI will use %.2f and continue.', usersValue2);
uiwait(warndlg(message));
end
Related Question