GUI中的str2num对话框matlab
我正试图纠正这段代码,其中用户将输入a和b的值,但b必须大于a。因此,代码将对其进行测试,在出现错误回复时,会出现一个对话框,询问用户希望重新输入哪个值,用户将单击一个按钮,该按钮将引导他进入另一个对话框,该对话框将询问他a或b的值,然后检查输入的新值。我需要这些值作为数字出来,以便以后进行一些计算,但我无法让我的代码正常工作,以下是我到目前为止得到的结果:GUI中的str2num对话框matlab,matlab,user-interface,Matlab,User Interface,我正试图纠正这段代码,其中用户将输入a和b的值,但b必须大于a。因此,代码将对其进行测试,在出现错误回复时,会出现一个对话框,询问用户希望重新输入哪个值,用户将单击一个按钮,该按钮将引导他进入另一个对话框,该对话框将询问他a或b的值,然后检查输入的新值。我需要这些值作为数字出来,以便以后进行一些计算,但我无法让我的代码正常工作,以下是我到目前为止得到的结果: if str2num(b) <= str2num(a); %convert value to doulbe to run the t
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
如果str2num(b)出现什么错误消息?在赋值A(I)=b中,b和I中的元素数必须相同。无标题>按钮1_回调(第168行)dt(时间)=a.*cosd(t)+sqrt(i)中出错;gui_mainfcn(第96行)feval(varargin{:})中出错;无标题(第17行)gui_mainfcn(gui_状态,varargin{:})中的错误;计算uicontrol回调时@(hObject,eventdata)untitled('button1_Callback',hObject,eventdata,guidata(hObject))错误