📄 signal.asv
字号:
yleft=1.25:0.01:2.75;
xleft=zeros(1,151)+y(kt+1);
%创建汽车图形的右边
yright=yleft;
xright=xleft+(ymax-ymin)/20;
%创建汽车在坐标上的上边,下边
xx=xleft:(ymax-ymin)/2000:xright;
gtop=ones(1,length(xx))*1.25;
fbottom=ones(1,length(xx)).*2.75;
%为了在曲线绘制中途强制退出而造成坐标系声明错误,特用exit来判断一下
if exit==0 & pauseture==0
axes(handles.drawmovie);%指定汽车坐标系
%画出汽车图形
plot(xleft,yleft,'g'),
axis([ymin,ymax+(ymax-ymin)/20,0,3.5]);%动态选择坐标范围
%标记坐标轴
xlabel('汽车移动演示->自然响应','FontSize',10);
ylabel('长方形代表汽车','FontSize',10);
box off;hold on;%关闭汽车坐标系的右边和上边的坐标显示及保持住图形
plot(xright,yright,'g'),axis([ymin,ymax+(ymax-ymin)/20,0,3.5]);%动态选择坐标范围
plot(xx,gtop,'g'),axis([ymin,ymax+(ymax-ymin)/20,0,3.5]);%动态选择坐标范围
plot(xx,fbottom,'g'),axis([ymin,ymax+(ymax-ymin)/20,0,3.5]);%动态选择坐标范围
hold off;
%为了在曲线绘制中途强制退出而造成坐标系声明错误,特用exit来判断一下
end
if exit==0 & pauseture==0
axes(handles.drawcurve);%指定位移变化坐标系
plot(ta,y,'b'),grid on,%画出曲线
axis([0,time,ymin,ymax+(ymax-ymin)/20]);%使曲线坐标保持一致并动态选择坐标范围
%标记坐标轴
xlabel('时间->自然响应','FontSize',10);
ylabel('路程->自然响应','FontSize',10);
end
if exit==0 & pauseture==0
axes(handles.drawspeed);%指定速度坐标系
plot(ta,dy,'c'),grid on,%画出曲线
axis([0,time,dymin,dymax+(dymax-dymin)/20]);%使曲线坐标保持一致并动态选择坐标范围
%标记坐标轴
xlabel('时间->自然响应','FontSize',10);
ylabel('速度->自然响应','FontSize',10);
end
end
end
set(handles.jieyue,'Enable','on');%开启阶跃响应按钮的可用性
else
msgbox('输入各项的值必须(M,Kf,Speed,Time)>0,才符合实际,请重新输入!','提示:');
end
% --- Executes on button press in jieyue.
function jieyue_Callback(hObject, eventdata, handles)
% hObject handle to jieyue (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%求解阶跃响应
global exit;
global pauseture;
set(handles.ziran,'Enable','off');%关闭自然响应按钮的可用性
m=str2double(get(handles.shurum,'String'));%从输入框中获取质量值
kf=str2double(get(handles.shurukf,'String'));%从输入框中获取摩擦系数值
time=str2double(get(handles.shurutime,'String'));%从输入框中获取响应显示时间范围值
%利用拉普拉斯算子求解阶跃响应,Y(s)=B(s)/A(s),在时间域的解是y(t)是Y(s)的普拉斯的反变换
if m & kf & time%判断输入各项值是否符合实际
set(handles.ziran,'Enable','off');%关闭自然响应按钮的可用性
a=[m,kf,0,0];%B(s)
b=[1];%A(s)
[r1,p1,k1]=residue(b,a);%将多项式分解为多个一项分式之和,residue可完成这一任务
t=0:0.1:time;
%求出阶跃响应在此时间范围内的最大值和最小值
for kt=0:1:length(t)
tqiu(kt+1)=kt*0.1;
yqiu=r1(1)*exp(p1(1)*tqiu)+r1(2)+r1(3)*tqiu;%阶跃响应的位移方程
dyqiu=r1(1)*p1(1)*exp(p1(1)*tqiu)+r1(3);%阶跃响应的速度方程
end
ymax=max(yqiu);
ymin=min(yqiu);
dymax=max(dyqiu);
dymin=min(dyqiu);
%不断构建汽车移动和阶跃响应曲线的动画,并使他们相互联系
exit=0;%为了消除退出后再重新进入时可能exit为1仍在系统中,特消除一下
pauseture=0;%为了消除退出后再重新进入时可能pauseture为1仍在系统中,特消除一下
for kt=0:1:length(t)
if exit==1
close;
else
ta(kt+1)=kt*0.1;
y=r1(1)*exp(p1(1)*ta)+r1(2)+r1(3)*ta;%阶跃响应的位移方程
dy=r1(1)*p1(1)*exp(p1(1)*ta)+r1(3);%阶跃响应的速度方程
%创建汽车图形的左边
yleft=1.25:0.01:2.75;
xleft=zeros(1,151)+y(kt+1);
%创建汽车图形的右边
yright=yleft;
xright=xleft+(ymax-ymin)/20;
%创建汽车在坐标上的上边,下边
xx=xleft:(ymax-ymin)/2000:xright;
gtop=ones(1,length(xx)).*1.25;
fbottom=ones(1,length(xx)).*2.75;
%为了在曲线绘制中途强制退出而造成坐标系声明错误,特用exit来判断一下
if exit==0 & pauseture==0
axes(handles.drawmovie);%指定汽车坐标系
%画出汽车图形
plot(xleft,yleft,'g'),axis([ymin,ymax+(ymax-ymin)/20,0,3.5]);%动态选择坐标范围
%标记坐标轴
xlabel('汽车移动演示->阶跃响应','FontSize',10);
ylabel('长方形代表汽车','FontSize',10);
box off;hold on;%关闭汽车坐标系的右边和上边的坐标显示及保持住图形
plot(xright,yright,'g'),axis([ymin,ymax+(ymax-ymin)/20,0,3.5]);%动态选择坐标范围
plot(xx,gtop,'g'),axis([ymin,ymax+(ymax-ymin)/20,0,3.5]);%动态选择坐标范围
plot(xx,fbottom,'g'),axis([ymin,ymax+(ymax-ymin)/20,0,3.5]);%动态选择坐标范围
hold off;
%为了在曲线绘制中途强制退出而造成坐标系声明错误,特用exit来判断一下
end
if exit==0 & pauseture==0
axes(handles.drawcurve);%指定位移变化坐标系
plot(ta,y,'m'),%画出曲线
grid on;
%标记坐标轴
xlabel('时间->阶跃响应','FontSize',10);
ylabel('路程->阶跃响应','FontSize',10);
axis([0,time,ymin,ymax+(ymax-ymin)/20]),%使曲线坐标保持一致并动态选择坐标范围
end
if exit==0 & pauseture==0
axes(handles.drawspeed);%指定速度坐标系
plot(ta,dy,'c'),%画出曲线
grid on;
%标记坐标轴
xlabel('时间->阶跃响应','FontSize',10);
ylabel('速度->阶跃响应','FontSize',10);
axis([0,time,dymin,dymax+(dymax-dymin)/20]),%使曲线坐标保持一致并动态选择坐标范围
end
end
end
set(handles.ziran,'Enable','on');%开启自然响应按钮的可用性
else
msgbox('输入各项的值(M,Kf,Time)必须>0,才符合实际,请重新输入!','提示:');
end
% --- Executes on button press in stopplay.
function stopplay_Callback(hObject, eventdata, handles)
global pauseture;
pauseture=1;
% hObject handle to stopplay (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in exitapl.
function exitapl_Callback(hObject, eventdata, handles)
% hObject handle to exitapl (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%退出确认对话框
global exit;
%目的:为了在曲线绘制中途强制退出而造成坐标系声明错误,特创建一个退出变量已避免出现错误
answer=questdlg('确定退出?','退出');
if strcmp(answer,'Yes')
exit=1;
close;
end
% --------------------------------------------------------------------
function aboutapl_Callback(hObject, eventdata, handles)
%制作小组名单显示
msgbox('梁威(E05620113)赵汀(E05620132)王吉(E05620117)潘燕均(E05620116)','制作小组');
% hObject handle to aboutapl (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function caozuo_Callback(hObject, eventdata, handles)
% hObject handle to caozuo (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function help_Callback(hObject, eventdata, handles)
% hObject handle to help (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
function shurutime_Callback(hObject, eventdata, handles)
% hObject handle to shurutime (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of shurutime as text
% str2double(get(hObject,'String')) returns contents of shurutime as a double
% --- Executes during object creation, after setting all properties.
function shurutime_CreateFcn(hObject, eventdata, handles)
% hObject handle to shurutime (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -