Effacer les filtres
Effacer les filtres

Using a menu to generate variables for larger code

4 vues (au cours des 30 derniers jours)
Luke Cabot
Luke Cabot le 8 Avr 2024
Déplacé(e) : Stephen23 le 8 Avr 2024
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!

Réponse acceptée

Stephen23
Stephen23 le 8 Avr 2024
Modifié(e) : Stephen23 le 8 Avr 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 commentaire
Luke Cabot
Luke Cabot le 8 Avr 2024
Déplacé(e) : Stephen23 le 8 Avr 2024
@Stephen23 thanks very much for this, thats solved what I am trying to do for now

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Simulink dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by