|
|
[求助]
GUI设计问题——拟合给定四个点的拟合曲线
各位大侠请帮忙!我打算设计一个gui界面,输入四个点的坐标,然后拟合曲线,输出曲线图形,一下是我已经做的工作,但是运行不出结果:
修改的程序部分如下:
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
t1=str2double(get(handles.t1_input,'string'))%t1t2t3t4v1v2v3v4是点对应的坐标
t2=str2double(get(handles.t2_input,'string'))
t3=str2double(get(handles.t3_input,'string'))
t4=str2double(get(handles.t4_input,'string'))
v1=str2double(get(handles.v1_input,'string'))
v2=str2double(get(handles.v2_input,'string'))
v3=str2double(get(handles.v3_input,'string'))
v4=str2double(get(handles.v4_input,'string'))
T=[t1 t2 t3 t4];%样本点横坐标(时间)的向量
V=[v1 v2 v3 v4];%样本点纵坐标(速度)的向量
v=polyfit(T,V,4);%速度曲线多项式拟合
axes(handles.tu_axes)%坐标图的tag为tu
plot(T,V,'r*');%画样本点
hold on;%保持当前绘图窗口,继续在此绘图窗口上画拟合曲线
t=(0:0.0001:0.028);%确定自变量值x
y2=polyval(v,t);%polyval函数求对应t的多项式的v值,
plot(t,y2);
grid on;%坐标图上画分格线
![]()
界面的截图 |
|