フィルターのクリア

Using a menu to generate variables for larger code

4 ビュー (過去 30 日間)
Luke Cabot
Luke Cabot 2024 年 4 月 8 日
移動済み: Stephen23 2024 年 4 月 8 日
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);
  1 件のコメント
Luke Cabot
Luke Cabot 2024 年 4 月 8 日
移動済み: Stephen23 2024 年 4 月 8 日
@Stephen23 thanks very much for this, thats solved what I am trying to do for now

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSimulink についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by