how to create an input window for more than two variables

21 次查看(过去 30 天)
according to https://www.mathworks.com/help/matlab/ref/inputdlg.html 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)

采纳的回答

Walter Roberson
Walter Roberson 2021-12-7
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 个评论
Manuel Arellano
Manuel Arellano 2021-12-7
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

请先登录,再进行评论。

更多回答(1 个)

Chunru
Chunru 2021-12-7
编辑:Chunru 2021-12-7
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
  3 个评论
Walter Roberson
Walter Roberson 2021-12-7
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
r2 = answer(2);
r3 = answer(3);
r4 = answer(4);
o2 = answer(5);
o2p = answer(6);
o2pp = answer(7);
Manuel Arellano
Manuel Arellano 2021-12-8
This is what i was thinking of i did not know i had to write it like that using answer, thank you very much

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by