我正试图纠正这个代码,其中用户输入a和for b的值,但b必须大于a。所以代码会对它进行测试,并且如果出现错误回复并且有一个对话框询问用户他想要重新输入哪个值,则用户会点击一个按钮,该按钮会引导他进入另一个应该问他的对话框对于a或b的值,然后检查输入的新值。我需要将这些值作为数字出来,以便稍后计算,但我无法使我的代码正常工作,这是我到目前为止所拥有的:
if str2num(b) <= str2num(a); %convert value to doulbe to run the test
promptMessage = sprintf('The value of the b is smaller or equal to the value of a, do you want to reinput the value of the a or the value of the b?' );
button = questdlg(promptMessage, 'Reinput value of a or b ?', 'a', 'b', 'Rod-Crank');
if strcmpi(button, 'a')
prompt = ('Please reenter the value of a:');
a=inputdlg(prompt);
while isnan(str2double(a)) || ~isreal(str2double(a)) || isinf(str2double(a)) || str2double(a) <= 0;
prompt = ('Please reenter the value of a:');
a=inputdlg(prompt);
end
c = char(a);
a=str2num(c(1));
b=str2num(b);
end
if strcmpi(button, 'b')
prompt = ('Please reenter the value of b:');
b=inputdlg(prompt);
while isnan(str2double(b)) || ~isreal(str2double(b)) || isinf(str2double(b)) || str2double (b) <= 0;
prompt = ('Please reenter the value of b:');
b=inputdlg(prompt);
end
c = char(b);
b=str2num(c(1));
a=str2num(a);
end
end
if isnan(str2double(f)) || ~isreal(str2double(f)) || isinf(str2double(f)) || isempty(f) || str2double (f) < 0; % test if the value of c is valid
promptMessage = sprintf('The value entered for the Frequency " %0.5g " is incorrect, Please reenter the value for Frequency ', f);
button = questdlg(promptMessage, 'Error in value of the Frequency.', 'Ok', 'Ok');
end
f = str2num(f);
for t = 0 : 1 : 360;
Time = t+1;
O = (2.*pi.*f)./60;
i = b.^2-a.^2.*((sind(t)).^2);
j = (a.^2).*(O).*sind(2.*t);
dt (Time) = a.*cosd(t)+ sqrt(i);
V (Time) = (-a.*O.*sind(t))-(j/(2.*(sqrt(i))));
A (Time) = (-a.*(O.^2).*cosd(t))-(4.*(a.^2).*(O.^2).*cosd(2.*t).*i + j.^2)/(4.*(i.^1.5));
y (Time) = t;
end