Clear Filters
Clear Filters

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

1 view (last 30 days)
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.

Answers (1)

Walter Roberson
Walter Roberson on 22 Apr 2019
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);

Categories

Find more on MATLAB in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!