필터 지우기
필터 지우기

Choice made in menu prints a blank box

조회 수: 3 (최근 30일)
Shawn Christensen
Shawn Christensen 2019년 1월 30일
답변: Pranjal Priyadarshi 2019년 2월 8일
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.

답변 (1개)

Pranjal Priyadarshi
Pranjal Priyadarshi 2019년 2월 8일
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.
s={'Yanny','Laural'};
D3=menu('Who do you hear?', s);
if(D3 == 0)
disp('No choice selected');
else
disp(sprintf('D3= \n%s',s{D3}));
end

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by