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

1 vue (au cours des 30 derniers jours)
mat geek
mat geek le 22 Avr 2019
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.

Réponses (1)

Walter Roberson
Walter Roberson le 22 Avr 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);

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by