how to create an input window for more than two variables

16 vues (au cours des 30 derniers jours)
Manuel Arellano
Manuel Arellano le 7 Déc 2021
Commenté : Manuel Arellano le 8 Déc 2021
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)

Réponse acceptée

Walter Roberson
Walter Roberson le 7 Déc 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 commentaire
Manuel Arellano
Manuel Arellano le 7 Déc 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

Connectez-vous pour commenter.

Plus de réponses (1)

Chunru
Chunru le 7 Déc 2021
Modifié(e) : Chunru le 7 Déc 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 commentaires
Walter Roberson
Walter Roberson le 7 Déc 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 le 8 Déc 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

Connectez-vous pour commenter.

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by