Using a menu to generate variables for larger code

32 views (last 30 days)
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!

Accepted Answer

Stephen23
Stephen23 on 8 Apr 2024 at 10:47
Edited: Stephen23 on 8 Apr 2024 at 11:04
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);
  1 Comment
Luke Cabot
Luke Cabot on 8 Apr 2024 at 11:32
Moved: Stephen23 on 8 Apr 2024 at 19:26
@Stephen23 thanks very much for this, thats solved what I am trying to do for now

Sign in to comment.

More Answers (0)

Categories

Find more on Simulink in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!