MATLAB Dialog Boxes Help
조회 수: 8 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Star Strider
2019년 12월 19일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Performance and Memory에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!