二、部分源代码

function varargout = dianti(varargin)
% DIANTI M-file for dianti.fig
% DIANTI, by itself, creates a new DIANTI or raises the existing
% singleton*.
%
% H = DIANTI returns the handle to a new DIANTI or the handle to
% the existing singleton*.
%
% DIANTI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in DIANTI.M with the given input arguments.
%
% DIANTI('Property','Value',...) creates a new DIANTI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before dianti_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to dianti_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 dianti

% Last Modified by GUIDE v2.5 19-Dec-2020 21:36:37

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @dianti_OpeningFcn, ...
'gui_OutputFcn', @dianti_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 dianti is made visible.
function dianti_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 dianti (see VARARGIN)

% Choose default command line output for dianti
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes dianti wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = dianti_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 edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (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 edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double


% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (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 edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double


% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over text3.
function text3_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to text3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function Untitled_1_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_1 (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 pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%x1=str2num(get(handles.edit1,'string'));%你所在楼层
%x2=str2num(get(handles.edit2,'string'));%你要去的楼层
clear all;
figure('name','自控电梯');
axis([-2.0,15.0,-2.0,15.0])%坐标轴的范围
hold on
fill([-2,15,15,-2],[-2,-2,15,15],[0.4,0.2,0.2]);
x1=[9.5 9.5 10 10];
y1=[0.5 0 0 0.5];
x2=[10 10 10.5 10.5];
text(-1,8,'上升','fontsize',7,'color','c');
text(4,8,'下降','fontsize',7,'color','c');
text(6,12.5,'控制电机','fontsize',7,'color','c');
%text(12.5,3,'电梯','fontsize',10,'color','c');
%text(5,4.5,'关闭','fontsize',10,'color','c');
%text(5,1.5,'打开','fontsize',10,'color','c');
l1=line([2;5.5],[13;13],'color','c','linestyle','-','linewidth',2);
l2=line([2;2],[11;13],'color','c','linestyle','-','linewidth',2);
l3=line([1;1],[9;11],'color','c','linestyle','-','linewidth',2);
l4=line([3;3],[9;11],'color','c','linestyle','-','linewidth',2);
l5=line([1;3],[11;11],'color','c','linestyle','-','linewidth',2);%绘制导线
k1=line([2;1],[8;9],'color','r','linestyle','-','linewidth',2);%单刀双掷开关
%k2=line([4;5],[3;4],'color','b','linestyle','-','linewidth',2);%单刀双掷开关
%g1=line([7.7;8],[3;3],'color','b','linestyle','-','linewidth',2);
%g2=line([7.7;7.7],[3;4],'color','b','linestyle','-','linewidth',2);
%g3=line([7.4;7.7],[2;4],'color','b','linestyle','-','linewidth',2);
%g4=line([7.4;7.4],[2;4],'color','b','linestyle','-','linewidth',2);
%g5=line([7.1;7.4],[2;4],'color','b','linestyle','-','linewidth',2);
%g6=line([7.1;7.1],[2;4],'color','b','linestyle','-','linewidth',2);
%g7=line([6.8;7.1],[2;4],'color','b','linestyle','-','linewidth',2);
%g8=line([6.8;6.8],[2;4],'color','b','linestyle','-','linewidth',2);
%g9=line([6.5;6.8],[2;4],'color','b','linestyle','-','linewidth',2);
%g10=line([6.5;6.5],[2;3],'color','b','linestyle','-','linewidth',2);
%g11=line([6.0;6.5],[3;3],'color','b','linestyle','-','linewidth',2);
%g12=line([6;6],[2;4],'color','c','linestyle','-','linewidth',2);
%g13=line([5;6],[2;2],'color','c','linestyle','-','linewidth',2);
%g14=line([5;6],[4;4],'color','c','linestyle','-','linewidth',2);%绘制电梯门伸缩控制开关
door1=patch(x1,y1,[0 1 1]);
door2=patch(x2,y1,[0 1 1]);%画电梯的两面门
t=0:pi/100:2*pi;
fill(6+0.5*sin(t),13+cos(t),[0.7,0.85,0.9]);%电机左端
fill(8.5+0.5*sin(t),13+cos(t),[0.7,0.85,0.9]);%电机右端
e0=line([9;10],[13;13],'color','r','linewidth',2);%
e1=line([10;10],[0.5;13],'color','b','linewidth',2);%连接电机中轴和电梯的线
%画电机的表面(用八根不同颜色的线代替,每根之间相差pi/4
%为简便起见,初始条件下可将八根线分成两组放在电机的顶端和底端
s1=line([6;8.5],[14;14],'color','c','linestyle','-','linewidth',2);
s2=line([6;8.5],[12;12],'color','m','linestyle','-','linewidth',2);
s3=line([6;8.5],[14;14],'color','b','linestyle','-','linewidth',2);
s4=line([6;8.5],[12;12],'color','w','linestyle','-','linewidth',2);
s5=line([6;8.5],[14;14],'color','k','linestyle','-','linewidth',2);
s6=line([6;8.5],[12;12],'color','g','linestyle','-','linewidth',2);
s7=line([6;8.5],[14;14],'color','r','linestyle','-','linewidth',2);
s8=line([6;8.5],[12;12],'color','b','linestyle','-','linewidth',2);
a=0; %设定电机运转的初始角度
da=0.05;%设定电机正转的条件
s=0; %设定门运动的初始条件
ds=0.05;%设定门运动的周期

三、运行结果

【机械仿真】基于matlab GUI智能电梯仿真系统【含Matlab源码 1087期】_ide

【机械仿真】基于matlab GUI智能电梯仿真系统【含Matlab源码 1087期】_matlab_02

四、matlab版本及参考文献

1 matlab版本

2014a

2 参考文献

[1] 门云阁.MATLAB物理计算与可视化[M].清华大学出版社,2013.