www.gusucode.com > 基于GUI界面的比例导引弹道仿真matlab源码程序 > 基于GUI界面的比例导引弹道仿真matlab源码程序/qzy33.m
function varargout = qzy33(varargin) % QZY33 M-file for qzy33.fig % QZY33, by itself, creates a new QZY33 or raises the existing % singleton*. % % H = QZY33 returns the handle to a new QZY33 or the handle to % the existing singleton*. % % QZY33('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in QZY33.M with the given input arguments. % % QZY33('Property','Value',...) creates a new QZY33 or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before qzy33_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to qzy33_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 qzy33 % Last Modified by GUIDE v2.5 15-Dec-2007 16:55:10 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @qzy33_OpeningFcn, ... 'gui_OutputFcn', @qzy33_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin & isstr(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 qzy33 is made visible. function qzy33_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 qzy33 (see VARARGIN) %uicontrol(gcf,'Style','Frame',... % 'Units','normalized',... % 'Position',[.84,.018,.002,.923],... % 'Back',[.5 .5 .5]); %set(gcf,'NumberTitle',''); %set(gcf,'menubar','none'); set(handles.K,'visible','off'); set(handles.K1,'visible','off'); % Choose default command line output for qzy33 handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes qzy33 wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = qzy33_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; % --- Executes on button press in push_start. function push_start_Callback(hObject, eventdata, handles) % hObject handle to push_start (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) %最优制导率仿真,初始化参数 global signvc; g=9.81; pi=3.14159265; tgst=get(handles.pop_t,'value'); k=str2num(get(handles.K,'string')); vm=str2num(get(handles.vm,'string')); vt=str2num(get(handles.vt,'string'));%导弹和目标的速度 mtc=vm/vt; headerror=str2num(get(handles.headerror,'string'))*pi/180; %指向角误差 thetat=str2num(get(handles.thetat,'string'))*pi/180; %目标的速度方向 rmx=0;rmy=0; rtx=str2num(get(handles.tx,'string')); %初始目标坐标X rty=str2num(get(handles.ty,'string')); %初始目标坐标Y at=str2num(get(handles.at,'string'))*g;%目标法向加速度 vtx=vt*sin(thetat);%目标的速度分量 vty=vt*cos(thetat); rtmx=rtx-rmx;%弹目相对距离 rtmy=rty-rmy; ammax=str2num(get(handles.ammax,'string'))*g;%导弹的最大机动能力为15g rtm=sqrt(rtmx^2+rtmy^2); sightangle=atan(rtmx/rtmy);%视线角 leadangle=asin(vt*sin(sightangle-thetat)/vm);%指向角 vmx=vm*sin(sightangle-leadangle+headerror);%导弹的速度分量 vmy=vm*cos(sightangle-leadangle+headerror); vtmx=vtx-vmx; vtmy=vty-vmy; %弹目的相对运动速度 vc=-(rtmx*vtmx+rtmy*vtmy)/rtm; signvc=sign(vc); %vc的符号 time=0;timestep=str2num(get(handles.dt,'string'));%时间和时间步长 %file=fopen('output.dat','wt');%将数据写入文件 %循环 while(1) %vc改变符号仿真结束 if(sign(vc)~=signvc) break; else if(rtm<100)%弹目距离小于100,步长变为0.005 timestep=0.005; end signvc=sign(vc); %视线角速率 dsightangle=(rtmy*vtmx-rtmx*vtmy)/(rtm^2); if (tgst==1) dtheta=3*vc*dsightangle/vm;%最优导引律 end if (tgst==2) dtheta=k*vc*dsightangle/vm;%比例导引 end if (tgst==3) dtheta=3*(vc*dsightangle+0.5*at)/vm; %加速度修正项 %dtheta=(vc*rtm^3/(vc^3+3*rtm^3))*dsightangle; end theta=atan(vmx/vmy); %导弹加速度 am=vm*dtheta; %限制机动能力 if(abs(am)>ammax) am=sign(am)*ammax; end %加速度分量 amx=am*cos(sightangle); amy=-am*sin(sightangle); amfa=am*cos(sightangle-theta); time=time+timestep; %if(time>=5) %at=-1*g*sign(sin(pi*(time-5)/10)); %目标作开关机动每10秒一次 %end %目标位置 rtx=rtx+timestep*vtx; rty=rty+timestep*vty; dthetat=at/vt; thetat=thetat+timestep*dthetat; vtx=vt*sin(thetat);%目标的速度分量 vty=vt*cos(thetat); %导弹位置 rmx=rmx+timestep*vmx; rmy=rmy+timestep*vmy; rm=sqrt(rmx^2+rmy^2); %导弹速度 vmx=vmx+timestep*amx; vmy=vmy+timestep*amy; vm=sqrt(vmx^2+vmy^2); %弹目相对位移 rtmx=rtx-rmx; rtmy=rty-rmy; %上一步的脱靶量 rtm0=rtm; rtm=sqrt(rtmx^2+rtmy^2); sightangle=atan(rtmx/rtmy);%视线角 %弹目相对速度 vtmx=vtx-vmx; vtmy=vty-vmy; vc=-(rtmx*vtmx+rtmy*vtmy)/rtm; if(abs(rtm)<2) break; end %数据写入文件 %fprintf(file,'%f %f %f %f %f %f %f %f \n',time,rmx,rmy,rtx,rty,sqrt(amx^2+amy^2),rtm,am); h1=subplot(handles.h1);plot(rmy,rmx,'b',rty,rtx,'r'),hold on, h2=subplot(handles.h2);plot(time,amfa/9.81),hold on,%画出法向过载随时间的变化 %h3=subplot(handles.h3);plot(time,vm),hold on, h3=subplot(handles.h3);plot(time,sightangle*57.3),hold on, h4=subplot(handles.h4);plot(time,dsightangle*57.3),hold on, end end tbl=rtm; zysj=time; fxgz=amfa/9.81; reset(h1); reset(h2); reset(h3); reset(h4); set(handles.zysj,'string',zysj); set(handles.tbl,'string',tbl); set(handles.mtc,'string',mtc); set(get(h1,'xlabel'),'string','x (m)'); set(get(h1,'ylabel'),'string','y (m)'); legend(h1,'导弹','目标',0); set(get(h1,'title'),'string','弹道曲线'); set(get(h2,'xlabel'),'string','时间t (s)'); set(get(h2,'ylabel'),'string','法向过载am (g)'); set(get(h2,'title'),'string','法向过载随时间的变化'); set(get(h3,'xlabel'),'string','时间t (s)'); %set(get(h3,'ylabel'),'string','导弹速度vm (m/s)'); %set(get(h3,'title'),'string','导弹速度随时间的变化'); set(get(h3,'ylabel'),'string','视线角q (\circ)'); set(get(h3,'title'),'string','视线角随时间的变化'); set(get(h4,'xlabel'),'string','时间t (s)'); set(get(h4,'ylabel'),'string','视线转率\theta (\circ)'); set(get(h4,'title'),'string','视线转率随时间的变化'); grid(h1); grid(h2); grid(h3); grid(h4); %status=fclose(file); % --- Executes on button press in push_return. function push_return_Callback(hObject, eventdata, handles) % hObject handle to push_return (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) close(gcf);mb;clear; % --- Executes during object creation, after setting all properties. function vm_CreateFcn(hObject, eventdata, handles) % hObject handle to vm (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 vm_Callback(hObject, eventdata, handles) % hObject handle to vm (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 vm as text % str2double(get(hObject,'String')) returns contents of vm as a double % --- Executes during object creation, after setting all properties. function vt_CreateFcn(hObject, eventdata, handles) % hObject handle to vt (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 vt_Callback(hObject, eventdata, handles) % hObject handle to vt (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 vt as text % str2double(get(hObject,'String')) returns contents of vt as a double % --- Executes during object creation, after setting all properties. function dt_CreateFcn(hObject, eventdata, handles) % hObject handle to dt (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 dt_Callback(hObject, eventdata, handles) % hObject handle to dt (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 dt as text % str2double(get(hObject,'String')) returns contents of dt as a double % --- Executes during object creation, after setting all properties. function headerror_CreateFcn(hObject, eventdata, handles) % hObject handle to headerror (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 headerror_Callback(hObject, eventdata, handles) % hObject handle to headerror (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 headerror as text % str2double(get(hObject,'String')) returns contents of headerror as a double % --- Executes during object creation, after setting all properties. function thetat_CreateFcn(hObject, eventdata, handles) % hObject handle to thetat (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 thetat_Callback(hObject, eventdata, handles) % hObject handle to thetat (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 thetat as text % str2double(get(hObject,'String')) returns contents of thetat as a double % --- Executes during object creation, after setting all properties. function at_CreateFcn(hObject, eventdata, handles) % hObject handle to at (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 at_Callback(hObject, eventdata, handles) % hObject handle to at (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 at as text % str2double(get(hObject,'String')) returns contents of at as a double % --- Executes during object creation, after setting all properties. function ammax_CreateFcn(hObject, eventdata, handles) % hObject handle to ammax (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 ammax_Callback(hObject, eventdata, handles) % hObject handle to ammax (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 ammax as text % str2double(get(hObject,'String')) returns contents of ammax as a double % --- Executes during object creation, after setting all properties. function h2_CreateFcn(hObject, eventdata, handles) % hObject handle to h2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: place code in OpeningFcn to populate h2 % --- Executes during object creation, after setting all properties. function pop_t_CreateFcn(hObject, eventdata, handles) % hObject handle to pop_t (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu 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 % --- Executes on selection change in pop_t. function pop_t_Callback(hObject, eventdata, handles) % hObject handle to pop_t (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,'String') returns pop_t contents as cell array % contents{get(hObject,'Value')} returns selected item from pop_t tgst1=get(handles.pop_t,'value'); if (tgst1==1||tgst1==3) set(handles.K,'visible','off'); set(handles.K1,'visible','off'); end if (tgst1==2) set(handles.K,'visible','on'); set(handles.K1,'visible','on'); end % --- Executes during object creation, after setting all properties. function K_CreateFcn(hObject, eventdata, handles) % hObject handle to K (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 K_Callback(hObject, eventdata, handles) % hObject handle to K (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 K as text % str2double(get(hObject,'String')) returns contents of K as a double % -------------------------------------------------------------------- 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) % -------------------------------------------------------------------- function Exit_Callback(hObject, eventdata, handles) % hObject handle to Exit (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) close(qzy33); % -------------------------------------------------------------------- function Untitled_4_Callback(hObject, eventdata, handles) % hObject handle to Untitled_4 (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) guanyu; % -------------------------------------------------------------------- function Rotate3d_Callback(hObject, eventdata, handles) % hObject handle to Rotate3d (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) rotate3d; % -------------------------------------------------------------------- function zoom_in_Callback(hObject, eventdata, handles) % hObject handle to zoom_in (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) zoom on; % -------------------------------------------------------------------- function zoom_out_Callback(hObject, eventdata, handles) % hObject handle to zoom_out (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) zoom out; % --- Executes during object creation, after setting all properties. function tx_CreateFcn(hObject, eventdata, handles) % hObject handle to tx (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 tx_Callback(hObject, eventdata, handles) % hObject handle to tx (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 tx as text % str2double(get(hObject,'String')) returns contents of tx as a double % --- Executes during object creation, after setting all properties. function edit11_CreateFcn(hObject, eventdata, handles) % hObject handle to edit11 (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 edit11_Callback(hObject, eventdata, handles) % hObject handle to edit11 (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 edit11 as text % str2double(get(hObject,'String')) returns contents of edit11 as a double % --- Executes during object creation, after setting all properties. function ty_CreateFcn(hObject, eventdata, handles) % hObject handle to ty (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 ty_Callback(hObject, eventdata, handles) % hObject handle to ty (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 ty as text % str2double(get(hObject,'String')) returns contents of ty as a double % --- Executes during object creation, after setting all properties. function mtc_CreateFcn(hObject, eventdata, handles) % hObject handle to mtc (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 mtc_Callback(hObject, eventdata, handles) % hObject handle to mtc (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 mtc as text % str2double(get(hObject,'String')) returns contents of mtc as a double % --- Executes during object creation, after setting all properties. function zysj_CreateFcn(hObject, eventdata, handles) % hObject handle to zysj (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 zysj_Callback(hObject, eventdata, handles) % hObject handle to zysj (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 zysj as text % str2double(get(hObject,'String')) returns contents of zysj as a double % --- Executes during object creation, after setting all properties. function tbl_CreateFcn(hObject, eventdata, handles) % hObject handle to tbl (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 tbl_Callback(hObject, eventdata, handles) % hObject handle to tbl (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 tbl as text % str2double(get(hObject,'String')) returns contents of tbl as a double