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 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