how to create an input window for more than two variables

2 views (last 30 days)
according to i should be able to make a single input window to give values to r1, r2, r3, r4, o2, o2p, o2pp. however, it only comes up with one tiny window for r1 and at that it defines r1 as 'r1' in the workspace. is there a way i can create one large window to input all the numbers needed for the variables. my script is to run and test multiple values so this is the reason i am attempting an input window so when i run my script i can change the values for each run of the script.
prompt = 'r1','r2','r3','r4','o2';'o2p','o2pp';
dlgtitle = 'input';
answer = inputdlg(prompt,dlgtitle)

Accepted Answer

Walter Roberson
Walter Roberson on 7 Dec 2021
prompt = {'r1','r2','r3','r4','o2','o2p','o2pp'};
Note that the collected response will be a cell array of character vectors; you mgiht want to str2double()
  1 Comment
Manuel Arellano
Manuel Arellano on 7 Dec 2021
i did do str2double previously
r1 = str2double(inputdlg('Value of r1:'));
r2 = str2double(inputdlg('Value of r2:'));
r3 = str2double(inputdlg('Value of r3:'));
r4 = str2double(inputdlg('Value of r4:'));
o2 = str2double(inputdlg('Value of o2:'));
o2p = str2double(inputdlg('Value of o2p:'));
o2pp = str2double(inputdlg('Value of o2pp:'));
however when the code runs it is a different input window everytime . how would it be written to only show up in one window

Sign in to comment.

More Answers (1)

Chunru on 7 Dec 2021
Edited: Chunru on 7 Dec 2021
prompt = {'r1','r2','r3','r4','o2','o2p','o2pp'};
dlgtitle = 'input';
dims = [1, 35];
answer = inputdlg(prompt,dlgtitle,dims)
% Then answer{1} is r1, anser{2} is r2, and so on
% to convert to number
answer = str2double(answer);
r1 = answer(1); % and so on
Manuel Arellano
Manuel Arellano on 8 Dec 2021
This is what i was thinking of i did not know i had to write it like that using answer, thank you very much

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!