Using a menu to generate variables for larger code

4 次查看(过去 30 天)
Hi all! New user. I have a large number of input variables that I need to generate a GUI plot. I am trying to use a menu for the user interface to avoid cluttering the GUI with lots of choices. I would also like to populate the menu with default values. Here is my code:
choice = menu('Choose Car Parameters', 'Vehicle', 'Initial Conditions');
if choice == 1
prompt = {'Car Max Speed: Min 10, Max 90',...
'Drag Coefficient', 'Width (m)', 'Mass (Kg)',...
'Acceleration Duration (s)'};
dlg_title = 'Input Car Parameters';
num_lines = 1;
def = {'40','0.5','1.5','1500','4'};
answer = inputdlg(prompt, dlg_title, num_lines, def);
else
prompt = {'East Position (m)', 'West Position (m)',...
'Initial Velocity (m/s)',};
dlg_title = 'Input Initial Conditions';
num_lines = 1;
def = {'0','0','3'};
answer = inputdlg(prompt, dlg_title, num_lines, def);
end
All of the outputs are numbers, but they are returned in an array matrix. When I open up the matrix, no values are present. How would I use the menu choices to output, say, a velocity i.e.
V = 'initial velocity' + a * 'Acceleration Dureation(s)'
Thanks very much!

采纳的回答

Stephen23
Stephen23 2024-4-8
编辑:Stephen23 2024-4-8
For the 1st dialog box:
V = str2double(answer);
maxvel = V(1);
dragco = V(2);
width = V(3);
mass = V(4);
accdur = V(5);
For the 2nd dialog box:
V = str2double(answer);
eastpos = V(1);
westpos = V(2);
initvel = V(3);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by