Azzera filtri
Azzera filtri

Using a menu to generate variables for larger code

4 visualizzazioni (ultimi 30 giorni)
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!

Risposta accettata

Stephen23
Stephen23 il 8 Apr 2024
Modificato: Stephen23 il 8 Apr 2024
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 Commento
Luke Cabot
Luke Cabot il 8 Apr 2024
Spostato: Stephen23 il 8 Apr 2024
@Stephen23 thanks very much for this, thats solved what I am trying to do for now

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Simulink in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by