Effacer les filtres
Effacer les filtres

Choice made in menu prints a blank box

3 vues (au cours des 30 derniers jours)
Shawn Christensen
Shawn Christensen le 30 Jan 2019
Part c
% uses the menu command to ask the user wheather
% they hear "Yanny" or "Laurel", then stores their
% answer to the variable D3
first = 'Yanny';
second = 'Laurel';
D3 = menu('Who do you hear?',first,second);
% Part d
% Prints the results of the choice made in the menu
% which was stored in D3
disp(sprintf('D3 = \n%s',D3))
This prints a blank box and stores D3 as 1 or 2 depending on the selection made.
I need it to print Yanny or Laurel not 1,2 or a blank box.
Homework Question:
Write a line of code that shows the variable D3 and its value, without using fprintf.

Réponses (1)

Pranjal Priyadarshi
Pranjal Priyadarshi le 8 Fév 2019
In order to get the values of the options instead of the index we can pass the values in a cell array to the menu function. The output can be achieved in the following manner (without using the fprintf function):
This code should do the job for you.
D3=menu('Who do you hear?', s);
if(D3 == 0)
disp('No choice selected');
disp(sprintf('D3= \n%s',s{D3}));

Community Treasure Hunt

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

Start Hunting!

Translated by