フィルターのクリア

How not repeat the main loop, if other options are selected?

4 ビュー (過去 30 日間)
Madalena Francisco
Madalena Francisco 2023 年 1 月 17 日
コメント済み: Madalena Francisco 2023 年 1 月 17 日
Hello! I'm building a program, where I need to have the while true, so that until the user clicks exit, the program ends.
And that part I managed to do!
My problem is that there is a part of the program where the user is asked to input things in the command window, meanwhile, I believe the ''menu b'' turns invisible, but it remains there.
When the user has input everything in the command window, I introduce a new menu (''menu c''), but the program first displays the waitbar that was defined at the beginning, and if I click on a button in c, that '' invisible menu b'' will appear.
I don't want to introduce break command, because I don't want to get out of the loop, I need the loop, because other conditions are defined in it that will be needed later in the program.
What I want is that somehow my loop does not repeat itself when another menu is introduced and that menu b closes completely when the user is told to type in the command window, in order not to interrupt the flow of the code.
It´s a little complex what I´m asking, but if you could help me it would be really amazing! I wanna learn about this so much
Here it´s a shorter version of my program...
It might be some errors when u try to break the loop, but my longer version doesn't:
Hope u understand the problem! Thanks a lot!
clc,clear,close
while true
%Operation of menu a
if a==1
wb= waitbar(0,'Starting program, wait...'); % progress bar
for i = 1:1000
wait bar(i/1000);
end
delete(wb) % progress bar
b= menu('How do you intend to insert the experimental points?', ...
'Through a file','Manually','Backspace','Exit');
elseif a==2
break %Exit the program
end
if b==1 %Menu operation b
elseif b==2
a1= sprintf('To advance in the program, press 1: ');
b1=str2double(input(a1,'s'));
c= menu('Regarding the table values displayed in the Command Window:', ...
'I confirm the values','I want to reset the values','Exit');
if c==1
d= menu('example', ...
'example','I want to reset the values','Exit');
if d==3
break
end
else if b==4
break
end
end
end
end
  5 件のコメント
Madalena Francisco
Madalena Francisco 2023 年 1 月 17 日
Ahhh, Thank u so much!!
Madalena Francisco
Madalena Francisco 2023 年 1 月 17 日
Jan, I want to be able to handle the transitions between menus, and if I return, I want that the previous in the main loop doesn´t appear again.

サインインしてコメントする。

回答 (1 件)

Jan
Jan 2023 年 1 月 17 日
The description is not really clear. I assume, you want a list of menus to be selected one after the other. Then:
status = 0;
... Starting the code
while true
if status == 0
b = menu('How do you intend to insert the experimental points?', ...
'Through a file','Manually','Backspace','Exit');
stop = b == 4
status = 1;
elseif status == 1
c = menu('Regarding the table values displayed in the Command Window:', ...
'I confirm the values','I want to reset the values','Exit');
stop = c == 3;
status = 2;
elseif status == 2
... and so on
end
if stop
break;
end
end
Afterwards you have a,b,c,... defined and stop is 1, if the user has selected 'Exit' anywhere.
  1 件のコメント
Madalena Francisco
Madalena Francisco 2023 年 1 月 17 日
Sorry if I the description wasn´t clear, but your ideia of use ''standard indentation'', already helped!
Thanks a lot!
How interesting! So if I use command ''status'', will the code run step by step, presenting menus, without going back to the main loop, even if the user inputs something on command window?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by