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

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by