While loop for a menu

조회 수: 2 (최근 30일)
TS
TS 2015년 5월 3일
댓글: Muhammad Waqar 2021년 8월 23일
options=menu('Options','Report Quadrants','Plot Data','Avg. Dist.','Max Dist.','Print Ascii','Exit Program')
while (true) options<6
options=menu('Options','Report Quadrants','Plot Data','Avg. Dist.','Max Dist.','Print Ascii','Exit Program')
for options=6
break
end
end
I'm trying to create a while loop for a menu in order to have it remain until "exit program" is selected from the options menu. Somethings incorrect because the options value goes to 0 after the first choice.

채택된 답변

Nobel Mondal
Nobel Mondal 2015년 5월 3일
In my opinion, the proper way of doing this would be - using call-back functions. Please have a look if this documentation helps you. There are a few relevant examples as well.
doc uimenu
Please let me know, if this is not applicable for any specific requirement that you have.
  댓글 수: 1
TS
TS 2015년 5월 4일
This works just fine, I appreciate it!

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Image Analyst
Image Analyst 2015년 5월 4일
You could do this:
buttonNumber = 1; % Initialize
while buttonNumber < 6
buttonNumber = menu('Options','Report Quadrants','Plot Data',...
'Avg. Dist.','Max Dist.','Print Ascii','Exit Program')
if buttonNumber == 6
break; % Get out of the loop
end
% else do stuff based on buttonNumber
end
  댓글 수: 1
Muhammad Waqar
Muhammad Waqar 2021년 8월 23일
This is awesome...

댓글을 달려면 로그인하십시오.


Paulo Almeida
Paulo Almeida 2017년 11월 13일
Due to respect of this topic, i want to create a submenu inside one of the options, and when the user press "exit/back" ir returns t the previous menu (original one). It works just fine until i press "back" in the submenu option and it seems to enter in an infinite loop and it can't get out of the submenu.
  댓글 수: 1
Image Analyst
Image Analyst 2017년 11월 13일
Paulo, this link will solve your problems with your code https://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/ Since only you have your code, not us, we can't solve your problem directly. But that link will definitely allow you to solve it yourself.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Audio I/O and Waveform Generation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by