フィルターのクリア

how can I output an option from menu after the user has selected an option

1 回表示 (過去 30 日間)
mat geek
mat geek 2019 年 4 月 22 日
回答済み: Walter Roberson 2019 年 4 月 22 日
I have a menu that prompts the user to select one of 4 materials to make a bat.
BatMa = menu('choose the bat material','ash','hickory','maple','pine');
After some caluclations for cost, i need to output the following
  1. Producing ## MMM bats a week for ## weeks - ## total bats Where MMM is the material that the user selected.
I know that the menu does not return string, it return the value based on the option. so if option 1 was selected. BatMa = 1. if the user picked maple. BatMat = 3 and so on.
My problem is how can i store that as string if there is away.

回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 4 月 22 日
materials = {'ash', 'hicory', 'maple', 'pine'});
BatMa = menu('choose the bat material', materials);
if BatMa == 0; error('cancel'); end
chosen_material = materials{BatMa};
per_week = randi(500);
num_weeks = randi([5 20]);
fprintf('Producing %d %s bats a week for %d weeks - %d total bats\n', per_week, chosen_material, num_weeks, per_week*num_weeks);

カテゴリ

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

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by