how to create an input window for more than two variables

16 visualizzazioni (ultimi 30 giorni)
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)

Risposta accettata

Walter Roberson
Walter Roberson il 7 Dic 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 Commento
Manuel Arellano
Manuel Arellano il 7 Dic 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

Accedi per commentare.

Più risposte (1)

Chunru
Chunru il 7 Dic 2021
Modificato: Chunru il 7 Dic 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
  3 Commenti
Walter Roberson
Walter Roberson il 7 Dic 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
r2 = answer(2);
r3 = answer(3);
r4 = answer(4);
o2 = answer(5);
o2p = answer(6);
o2pp = answer(7);
Manuel Arellano
Manuel Arellano il 8 Dic 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

Accedi per commentare.

Categorie

Scopri di più su Programming in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by