Help using menu option

조회 수: 9 (최근 30일)
Cami Culp
Cami Culp 2021년 10월 24일
편집: Image Analyst 2021년 10월 24일
I am trying to write a code that a menu pops up and the user chooses between two options. Based off of what they choose, there are two different sections of code that would run. I am assuming I need an if statement after the menu option based off of what they choose to seperate between the two sections of code but I am not sure how to do that.

답변 (2개)

Chris
Chris 2021년 10월 24일
편집: Chris 2021년 10월 24일
How about a question dialog box?
This example shows how to set an integer based on the case, but you could put your sections of code in there too.

Image Analyst
Image Analyst 2021년 10월 24일
편집: Image Analyst 2021년 10월 24일
Example from the help:
list = {'Red','Yellow','Blue',...
'Green','Orange','Purple'};
[index, tf] = listdlg('ListString', list);
or try questdlg():
promptMessage = sprintf('Which option do you want?');
titleBarCaption = 'Which option?';
buttonText = questdlg(promptMessage, titleBarCaption, 'Option 1', 'Option 2', 'Option 1');
if contains(buttonText, '1', 'IgnoreCase', true)
% They selected option 1.
else
% They selected option 2.
end

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by