MATLAB Dialog Boxes Help

9 Ansichten (letzte 30 Tage)
Kerby
Kerby am 19 Dez. 2019
Beantwortet: Star Strider am 19 Dez. 2019
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});

Antworten (1)

Star Strider
Star Strider am 19 Dez. 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});
I use listdlg here since the menu documentation suggests not to use menu.
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.

Kategorien

Mehr zu Performance and Memory finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by