Can i add a string "answer" into another inputdlg (text) question?

1 view (last 30 days)
Lets say i first ask my 'user' a question about his/her name with inputdlg command, they input answer. i.e John. Then say i want to make a second question with previous user input included, lets say i want to ask a second with inputdlg command, to get answer on another question... i.e.... Hi 'John'<--(previous user input) , how fast can my car go? is this possible? if so, how?
Thanks in advance!

Answers (1)

Image Analyst
Image Analyst on 22 Nov 2016
Isak, try this code. Adapt as needed:
% Ask user for their name.
defaultValue = {'John'};
titleBar = 'Enter your name';
userPrompt = 'Enter your name';
caUserName = inputdlg(userPrompt, titleBar, 1, defaultValue);
if isempty(caUserName),return,end; % Bail out if they clicked Cancel.
usersName = caUserName{1}; % Convert from cell array to string.
defaultValue = {'100'};
userPrompt = sprintf('Hi, %s. How fast can your car go?', usersName);
caSpeed = inputdlg(userPrompt, titleBar, 1, defaultValue);
if isempty(caUserName),return,end; % Bail out if they clicked Cancel.
speed = str2double(caSpeed{1});
message = sprintf('%s, your car can go %f miles per hour.\n', usersName, speed);
uiwait(helpdlg(message));

Categories

Find more on Deep Learning Toolbox 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!