MATLAB Dialog Boxes Help
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello, I am trying to create dialog boxes that will hold values for three variables. When the menu pops up, the user inputs a start value, stop value, and step value for these 3 variables. However, variable inputs will overwrite one another and the input step values will not save in an array. How do I save the step values in an array?
For example, if for variable x
Start Value: 1
End Value: 10
Step Value: 1
How do I get it so it will save the step values in an array.
See code attached below. Thanks!
choice1 = menu('Choose a variable','x','y','z');
prompt = {'Enter Start Value','Enter End Value','Enter Step Value'};
dlg_title = 'Input Variables';
num_lines = 1;
def = {'','',''};
answer = inputdlg(prompt,dlg_title,num_lines,def);
start = str2double(answer{1});
stop = str2double(answer{2});
step = str2double(answer{3});
0 comentarios
Respuestas (1)
Star Strider
el 19 de Dic. de 2019
One approach:
lstprmt = {'Choose a variable'};
lstlist = {'x','y','z'};
choice1 = listdlg('PromptString',lstprmt, 'ListString',lstlist);
vrbl = lstlist{choice1}; % Variable Character
prompt = {'Enter Start Value','Enter End Value','Enter Step Value'};
dlg_title = 'Input Variables';
num_lines = 1;
def = {'','',''};
answer = inputdlg(prompt,dlg_title,num_lines,def);
start(choice1) = str2double(answer{1});
stop(choice1) = str2double(answer{2});
step(choice1) = str2double(answer{3});
This code uses the ‘choice1’ variable as an index into first the ‘lstlist’ cell array to store the chosen variable (if necesary), and then to use it as an array index for ‘start’ and the others. This way, the values are stored in an array, and in a position that can be used later with respect to each variable.
0 comentarios
Ver también
Categorías
Más información sobre Performance and Memory en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!