📄 signal.asv
字号:
function varargout = signal(varargin)
% SIGNAL M-file for signal.fig
% SIGNAL, by itself, creates a new SIGNAL or raises the existing
% singleton*.
%
% H = SIGNAL returns the handle to a new SIGNAL or the handle to
% the existing singleton*.
%
% SIGNAL('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SIGNAL.M with the given input arguments.
%
% SIGNAL('Property','Value',...) creates a new SIGNAL or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before signal_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to signal_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help signal
% Last Modified by GUIDE v2.5 08-Jun-2007 10:59:42
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @signal_OpeningFcn, ...
'gui_OutputFcn', @signal_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before signal is made visible.
function signal_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to signal (see VARARGIN)
%用长方形代表小车
%创建汽车图形的左边
yleft=1.25:0.01:2.75;
xleft=zeros(1,151);
%创建汽车图形的右边
yright=yleft;
xright=xleft+0.5;
%创建汽车在坐标系中的上边,下边
xx=xleft:0.01:xright;
gtop=ones(1,length(xx))*1.25;
fbottom=ones(1,length(xx)).*2.75;
axes(handles.drawmovie);%指定汽车坐标系
%画出汽车图形
plot(xleft,yleft,'g'),axis([0,11,0,3.5]);
box off;hold on;%关闭汽车坐标系的右边和上边的坐标显示及保持住图形
plot(xright,yright,'g'),axis([0,11,0,3.5]);
plot(xx,gtop,'g'),axis([0,11,0,3.5]);
plot(xx,fbottom,'g'),axis([0,11,0,3.5]);
%标记坐标轴
xlabel('汽车移动演示','FontSize',10);
ylabel('长方形代表汽车','FontSize',10);
axes(handles.drawcurve);%指定位移变化坐标系
axis([0,10,0,10.6]);grid on;box on;
%标记坐标轴
xlabel('时间','FontSize',10);
ylabel('路程','FontSize',10);
axes(handles.drawspeed);%指定速度坐标系
axis([0,10,0,10.6]);grid on;box on;
%标记坐标轴
xlabel('时间','FontSize',10);
ylabel('速度','FontSize',10);
% Choose default command line output for signal
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes signal wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = signal_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
function shurum_Callback(hObject, eventdata, handles)
% hObject handle to shurum (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 shurum as text
% str2double(get(hObject,'String')) returns contents of shurum as a double
% --- Executes during object creation, after setting all properties.
function shurum_CreateFcn(hObject, eventdata, handles)
% hObject handle to shurum (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
function shurukf_Callback(hObject, eventdata, handles)
% hObject handle to shurukf (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 shurukf as text
% str2double(get(hObject,'String')) returns contents of shurukf as a double
% --- Executes during object creation, after setting all properties.
function shurukf_CreateFcn(hObject, eventdata, handles)
% hObject handle to shurukf (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
function shuruspeed_Callback(hObject, eventdata, handles)
% hObject handle to shuruspeed (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 shuruspeed as text
% str2double(get(hObject,'String')) returns contents of shuruspeed as a double
% --- Executes during object creation, after setting all properties.
function shuruspeed_CreateFcn(hObject, eventdata, handles)
% hObject handle to shuruspeed (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
% --- Executes on button press in ziran.
function ziran_Callback(hObject, eventdata, handles)
% hObject handle to ziran (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;
m=str2double(get(handles.shurum,'String'));%从输入框中获取质量值
kf=str2double(get(handles.shurukf,'String'));%从输入框中获取摩擦系数值
speed=str2double(get(handles.shuruspeed,'String'));%从输入框中获取初始速度值
time=str2double(get(handles.shurutime,'String'));%从输入框中获取响应显示时间范围值
if m & kf & speed & time%判断输入各项值是否符合实际
set(handles.jieyue,'Enable','off');%关闭阶跃响应按钮的可用性
%求出响应的特征值
a=[m,kf,0];
y0=[0,speed];
p=roots(a);
v=rot90(vander(p));%创建范德蒙矩阵
c=v\y0';
t=0:0.1:time;
%求出自然响应在此时间范围内的最大值和最小值
for kt=0:1:length(t)
yqiu(kt+1)=c(1)*exp(p(1)*kt*0.1)+c(2)*exp(p(2)*kt*0.1);%自然响应的位移方程
dyqiu(kt+1)=c(1)*p(1)*0.1*exp(p(1)*kt*0.1)+c(2)*p(2)*0.1*exp(p(2)*kt*0.1);%自然响应的速度方程
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
y(kt+1)=c(1)*exp(p(1)*kt*0.1)+c(2)*exp(p(2)*kt*0.1);%自然响应的位移方程
dy(kt+1)=c(1)*p(1)*0.1*exp(p(1)*kt*0.1)+c(2)*p(2)*0.1*exp(p(2)*kt*0.1);%自然响应的速度方程
ta(kt+1)=kt*0.1;
%创建汽车图形的左边
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -