ユーザーが a と 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