各位大俠請(qǐng)幫忙!我打算設(shè)計(jì)一個(gè)gui界面,輸入四個(gè)點(diǎn)的坐標(biāo),然后擬合曲線,輸出曲線圖形,一下是我已經(jīng)做的工作,但是運(yùn)行不出結(jié)果:
修改的程序部分如下:
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是點(diǎn)對(duì)應(yīng)的坐標(biāo)
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];%樣本點(diǎn)橫坐標(biāo)(時(shí)間)的向量
V=[v1 v2 v3 v4];%樣本點(diǎn)縱坐標(biāo)(速度)的向量
v=polyfit(T,V,4);%速度曲線多項(xiàng)式擬合
axes(handles.tu_axes)%坐標(biāo)圖的tag為tu
plot(T,V,'r*');%畫(huà)樣本點(diǎn)
hold on;%保持當(dāng)前繪圖窗口,繼續(xù)在此繪圖窗口上畫(huà)擬合曲線
t=(0:0.0001:0.028);%確定自變量值x
y2=polyval(v,t);%polyval函數(shù)求對(duì)應(yīng)t的多項(xiàng)式的v值,
plot(t,y2);
grid on;%坐標(biāo)圖上畫(huà)分格線
![]()
界面的截圖 |