how to create an input window for more than two variables

조회 수: 16 (최근 30일)
Manuel Arellano
Manuel Arellano 2021년 12월 7일
댓글: Manuel Arellano 2021년 12월 8일
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