フィルターのクリア

One condition is not being fulfilled, and suddenly when i wrote on command window, give me a infinite menu, and i can not close it

3 ビュー (過去 30 日間)
Hello, in this program that I'm building, when b1==2, there is no fulfillment of that condition, and when I write in the window command, later an infinite menu appears... I don't understand why, I've tried everything and I don't understand because my idea is not working.
So the problem begins when the user chose: 'Manually'
If u respond on input 'a1' : 2, it´s not giving what it´s in the code, it gives me the condition b1==1, and appears the menu that i talked earlier.
please help, the code it´s:
clc, clear, close
while true
a=menu({'This program allows the fitting of functions to experimental points.', ...
'To start the program, click on the Start button.'},'Start','Exit');
%Operation of menu a
if a==1
b= menu('How do you intend to insert the experimental points?', ...
'By a file','Manually','Back','Exit');
end
if a==2
break
end
%Operation of the menu b
if b==1
elseif b==2
a1= sprintf('If you want to advance in the program, press 1.\n If you want to go back to the previous menu, press 2: ');
b1= input(a1);
p = input('How many experimental values do you want to insert?: ');
if b1==1
while p < 2 && p <= 0
errordlg ({'The number of experimental points must be at least 2.','Please press Ok and enter the desired value in the Command Window.'})
p = input('How many experimental values do you want to insert?: ');
end
n = p/2; %Number of matrix rows
m = 2; %Number of matrix columns
a = zeros(n,m); %prelocation
for i=1:n
for j=1:m
if (j == 1)
fprintf('Enter the %0.0fᵒ ',i)
a(i,j)= input('value of x: ');
else
fprintf('Enter the %0.0fᵒ ',i)
a(i,j)= input('value of y: ');
end
end
end
a=reshape(a,n,m); %Matrix according to the number of rows and columns
disp(a); %Matrix according to the number of rows and columns
end
if b1==2
clc
b= menu('How do you intend to insert the experimental points?', ...
'By a file','Manually','Back','Exit');
else
disp('The number entered was not correct')
end
if b==3
a=menu({'This program allows the fitting of functions to experimental points.', ...
'To start the program, click on the Start button.'},'Start','Exit');
if b==4
break
end
end
end
end
  2 件のコメント
Stephen23
Stephen23 2023 年 1 月 13 日
One of the changes that VBBV did, is to align the code consistently. Poorly aligned code hides the structure of the code, which makes it harder to understand (i.e. increases the risk of bugs and makes it harder to debug). You should consistently align your code. Note that the MATLAB editor can do this for you: select all code, press ctrl + i
Madalena Francisco
Madalena Francisco 2023 年 1 月 13 日
Wow and that´s amazing, I didn't know about that, thanks a lot Stephen! I have a Mac, where should i press? Thank u thank u!!

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

採用された回答

VBBV
VBBV 2023 年 1 月 13 日
編集済み: VBBV 2023 年 1 月 13 日
clc, clear, close
while true
a=menu({'This program allows the fitting of functions to experimental points.', ...
'To start the program, click on the Start button.'},'Start','Exit');
%Operation of menu a
if a==1
b= menu('How do you intend to insert the experimental points?', ...
'By a file','Manually','Back','Exit');
end
if a==2
break
end
%Operation of the menu b
if b==1
disp('Insert a file')
elseif b==2
a1 = input('If you want to advance in the program, press 1.\n If you want to go back to the previous menu, press 2: ');
b1 = a1 ;
if b1==1
p = input('How many experimental values do you want to insert?: '); % this statement
while p < 2 && p <= 0
errordlg ({'The number of experimental points must be at least 2.','Please press Ok and enter the desired value in the Command Window.'})
p = input('How many experimental values do you want to insert?: ');
end
n = p/2; %Number of matrix rows
m = 2; %Number of matrix columns
a = zeros(n,m); %prelocation
for i=1:n
for j=1:m
if (j == 1)
fprintf('Enter the %0.0fᵒ ',i)
a(i,j)= input('value of x: ');
else
fprintf('Enter the %0.0fᵒ ',i)
a(i,j)= input('value of y: ');
end
end
end
a=reshape(a,n,m); %Matrix according to the number of rows and columns
disp(a); %Matrix according to the number of rows and columns
elseif b1==2
clear b
b = menu('How do you intend to insert the experimental points?', ...
'By a file','Manually','Back','Exit');
else
disp('The number entered was not correct')
end
elseif b==3
a=menu({'This program allows the fitting of functions to experimental points.', ...
'To start the program, click on the Start button.'},'Start','Exit');
elseif b==4
break
end
end
  12 件のコメント
Madalena Francisco
Madalena Francisco 2023 年 1 月 13 日
編集済み: Madalena Francisco 2023 年 1 月 13 日
Thank u so much again!! Wow! And I let the final if b==4?
elseif b1==2
clear b
b = menu('How do you intend to insert the experimental points?', ...
'By a file','Manually','Back','Exit');
if b == 4 % i added this one and it works!
break
end
else
disp('The number entered was not correct')
end
elseif b==3
a=menu({'This program allows the fitting of functions to experimental points.', ...
'To start the program, click on the Start button.'},'Start','Exit');
elseif b==4 % but i need this one too right?
% Or i need to put below every b menu to close the program?
break
end
end
Madalena Francisco
Madalena Francisco 2023 年 1 月 13 日
Ok I think I understand... if I want the statments to work in each menu, their have to be below the menu is that it?

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

その他の回答 (0 件)

カテゴリ

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