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
2 次查看(过去 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
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
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Entering Commands 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!