2024-11-23 10:49:28
matlab的GUI中所有的控件的句柄都在handles结构体中,你直接打当然找不到了。获取句柄的方式如下:
mbfcxs1 =str2num( get(handles.mbfcxs1,'String'))
比如我下面这个拟合函数的GUI界面回调函数可以这样写
function start_Callback(hObject, eventdata, handles)
% hObject handle to start (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
try
delete(allchild(handles.axes1));
end
x1=str2num(get(handles.edit_x,'string'));
y1=str2num(get(handles.edit_y,'string'));
jc=str2num(get(handles.edit_jc,'string'));
rst=polyfit(x1,y1,jc(1));
as=poly2sym(rst)
xmax=max(x1);
xmin=min(x1);
xnum=2*length(x1)+100;
x2=linspace(xmin,xmax,xnum);
y2=polyval(rst,x2);
plot(x1,y1,'o',x2,y2);
set(handles.edit_rst,'string',num2str(rst));