1 简介 2 部分代码 function varargout = target_export(varargin) % TARGET_EXPORT M-file for target_export.fig % TARGET_EXPORT, by itself, creates a new TARGET_EXPORT or raises the existing % singleton*. % % H = TARGET_EXPORT returns
1 简介
2 部分代码
function varargout = target_export(varargin)% TARGET_EXPORT M-file for target_export.fig
% TARGET_EXPORT, by itself, creates a new TARGET_EXPORT or raises the existing
% singleton*.
%
% H = TARGET_EXPORT returns the handle to a new TARGET_EXPORT or the handle to
% the existing singleton*.
%
% TARGET_EXPORT('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in TARGET_EXPORT.M with the given input arguments.
%
% TARGET_EXPORT('Property','Value',...) creates a new TARGET_EXPORT or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before target_export_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to target_export_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 target_export
% Last Modified by GUIDE v2.5 09-Dec-2010 23:29:22
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @target_export_OpeningFcn, ...
'gui_OutputFcn', @target_export_OutputFcn, ...
'gui_LayoutFcn', @target_export_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 target_export is made visible.
function target_export_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 target_export (see VARARGIN)
%画靶子
draw;
% Choose default command line output for target_export
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes target_export wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = target_export_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 close.
function close_Callback(hObject, eventdata, handles)
% hObject handle to close (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close;
function uh_input_Callback(hObject, eventdata, handles)
% hObject handle to uh_input (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 uh_input as text
% str2double(get(hObject,'String')) returns contents of uh_input as a double
% --- Executes during object creation, after setting all properties.
function uh_input_CreateFcn(hObject, eventdata, handles)
% hObject handle to uh_input (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 vh_input_Callback(hObject, eventdata, handles)
% hObject handle to vh_input (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 vh_input as text
% str2double(get(hObject,'String')) returns contents of vh_input as a double
% --- Executes during object creation, after setting all properties.
function vh_input_CreateFcn(hObject, eventdata, handles)
% hObject handle to vh_input (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 vr_input_Callback(hObject, eventdata, handles)
% hObject handle to vr_input (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 vr_input as text
% str2double(get(hObject,'String')) returns contents of vr_input as a double
% --- Executes during object creation, after setting all properties.
function vr_input_CreateFcn(hObject, eventdata, handles)
% hObject handle to vr_input (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 ur_input_Callback(hObject, eventdata, handles)
% hObject handle to ur_input (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 ur_input as text
% str2double(get(hObject,'String')) returns contents of ur_input as a double
% --- Executes during object creation, after setting all properties.
function ur_input_CreateFcn(hObject, eventdata, handles)
% hObject handle to ur_input (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 ah_input_Callback(hObject, eventdata, handles)
% hObject handle to ah_input (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 ah_input as text
% str2double(get(hObject,'String')) returns contents of ah_input as a double
% --- Executes during object creation, after setting all properties.
function ah_input_CreateFcn(hObject, eventdata, handles)
% hObject handle to ah_input (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 ar_input_Callback(hObject, eventdata, handles)
% hObject handle to ar_input (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 ar_input as text
% str2double(get(hObject,'String')) returns contents of ar_input as a double
% --- Executes during object creation, after setting all properties.
function ar_input_CreateFcn(hObject, eventdata, handles)
% hObject handle to ar_input (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 bh_input_Callback(hObject, eventdata, handles)
% hObject handle to bh_input (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 bh_input as text
% str2double(get(hObject,'String')) returns contents of bh_input as a double
% --- Executes during object creation, after setting all properties.
function bh_input_CreateFcn(hObject, eventdata, handles)
% hObject handle to bh_input (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 br_input_Callback(hObject, eventdata, handles)
% hObject handle to br_input (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 br_input as text
% str2double(get(hObject,'String')) returns contents of br_input as a double
% --- Executes during object creation, after setting all properties.
function br_input_CreateFcn(hObject, eventdata, handles)
% hObject handle to br_input (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 distance_input_Callback(hObject, eventdata, handles)
% hObject handle to distance_input (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 distance_input as text
% str2double(get(hObject,'String')) returns contents of distance_input as a double
% --- Executes during object creation, after setting all properties.
function distance_input_CreateFcn(hObject, eventdata, handles)
% hObject handle to distance_input (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 sum_output_Callback(hObject, eventdata, handles)
% hObject handle to sum_output (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 sum_output as text
% str2double(get(hObject,'String')) returns contents of sum_output as a double
% --- Executes during object creation, after setting all properties.
function sum_output_CreateFcn(hObject, eventdata, handles)
% hObject handle to sum_output (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 average_output_Callback(hObject, eventdata, handles)
% hObject handle to average_output (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 average_output as text
% str2double(get(hObject,'String')) returns contents of average_output as a double
% --- Executes during object creation, after setting all properties.
function average_output_CreateFcn(hObject, eventdata, handles)
% hObject handle to average_output (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 n_output_Callback(hObject, eventdata, handles)
% hObject handle to n_output (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 n_output as text
% str2double(get(hObject,'String')) returns contents of n_output as a double
% --- Executes during object creation, after setting all properties.
function n_output_CreateFcn(hObject, eventdata, handles)
% hObject handle to n_output (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 start.
function start_Callback(hObject, eventdata, handles)
% hObject handle to start (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%画靶子
draw;
%清除输出结果
set(handles.sum_output,'string','');
set(handles.average_output,'string','');
set(handles.n_output,'string','');
set(handles.out1,'string','');
set(handles.out2,'string','');
set(handles.out3,'string','');
set(handles.out4,'string','');
set(handles.out5,'string','');
set(handles.out6,'string','');
set(handles.out7,'string','');
set(handles.out8,'string','');
set(handles.out9,'string','');
set(handles.out10,'string','');
%获取用户输入的武器参数和射击距离,没有输入则获取默认参数
uh=str2double(get(handles.uh_input,'string'));
ur=str2double(get(handles.ur_input,'string'));
vh=str2double(get(handles.vh_input,'string'));
vr=str2double(get(handles.vr_input,'string'));
ah=str2double(get(handles.ah_input,'string'));
ar=str2double(get(handles.ar_input,'string'));
bh=str2double(get(handles.bh_input,'string'));
br=str2double(get(handles.br_input,'string'));
distance=str2double(get(handles.distance_input,'string'));
%计算武器瞄准偏差和射弹散布偏差
Eh=uh*exp(vh*distance);
Er=vr*exp(vh*distance);
Bh=ah*power(distance,bh);
Br=ar*power(distance,br);
%在靶上标出位置,并且计算总环数、平均环数和命中率
sum=0;
average=0;
n=0;
single_score=0;
for m=1:10
h1=normrnd(0,Eh);
r1=normrnd(0,Er);
h2=normrnd(0,Bh);
r2=normrnd(0,Br);
h=(h1+h2)*10;
r=(r1+r2)*10;
%添加声音,其实是我自己录的音
[y,fs]=wavread('ak47.wav');
sound(y,fs);
switch fix(4*sqrtm(h.^2+r.^2))
case {0,1,2}
sum=sum+10;
n=n+1;
single_score=10;
axes(handles.target);
plot(h,r,'+');
case {3,4,5,6}
sum=sum+9;
n=n+1;
single_score=9;
axes(handles.target);
plot(h,r,'+');
case {7,8,9,10}
sum=sum+8;
n=n+1;
single_score=8;
axes(handles.target);
plot(h,r,'+');
case {11,12,13,14}
sum=sum+7;
n=n+1;
single_score=7;
axes(handles.target);
plot(h,r,'+');
case {15,16,17,18}
sum=sum+6;
n=n+1;
single_score=6;
axes(handles.target);
plot(h,r,'+');
otherwise
sum=sum;
n=n;
single_score=0;
end
%输出单词的结果
switch m
case 1
set(handles.out1,'string',num2str(single_score));
case 2
set(handles.out2,'string',num2str(single_score));
case 3
set(handles.out3,'string',num2str(single_score));
case 4
set(handles.out4,'string',num2str(single_score));
case 5
set(handles.out5,'string',num2str(single_score));
case 6
set(handles.out6,'string',num2str(single_score));
case 7
set(handles.out7,'string',num2str(single_score));
case 8
set(handles.out8,'string',num2str(single_score));
case 9
set(handles.out9,'string',num2str(single_score));
case 10
set(handles.out10,'string',num2str(single_score));
end
pause(1);
end
average=sum/10;
score=10*n;
%显示总环数,平均环数和命中率
set(handles.sum_output,'string',num2str(sum));
set(handles.average_output,'string',num2str(average));
set(handles.n_output,'string',num2str(score));
%弹出对话框,提示仿真完毕
helpdlg('仿真结束','提示');
% --- Executes on button press in clear.
function clear_Callback(hObject, eventdata, handles)
% hObject handle to clear (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%画靶子
draw;
%清除输出结果
set(handles.sum_output,'string','');
set(handles.average_output,'string','');
set(handles.n_output,'string','');
set(handles.out1,'string','');
set(handles.out2,'string','');
set(handles.out3,'string','');
set(handles.out4,'string','');
set(handles.out5,'string','');
set(handles.out6,'string','');
set(handles.out7,'string','');
set(handles.out8,'string','');
set(handles.out9,'string','');
set(handles.out10,'string','');
function out1_Callback(hObject, eventdata, handles)
% hObject handle to out1 (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 out1 as text
% str2double(get(hObject,'String')) returns contents of out1 as a double
% --- Executes during object creation, after setting all properties.
function out1_CreateFcn(hObject, eventdata, handles)
% hObject handle to out1 (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 out2_Callback(hObject, eventdata, handles)
% hObject handle to out2 (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 out2 as text
% str2double(get(hObject,'String')) returns contents of out2 as a double
% --- Executes during object creation, after setting all properties.
function out2_CreateFcn(hObject, eventdata, handles)
% hObject handle to out2 (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 out3_Callback(hObject, eventdata, handles)
% hObject handle to out3 (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 out3 as text
% str2double(get(hObject,'String')) returns contents of out3 as a double
% --- Executes during object creation, after setting all properties.
function out3_CreateFcn(hObject, eventdata, handles)
% hObject handle to out3 (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 out4_Callback(hObject, eventdata, handles)
% hObject handle to out4 (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 out4 as text
% str2double(get(hObject,'String')) returns contents of out4 as a double
3 仿真结果
4 参考文献
博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。
部分理论引用网络文献,若有侵权联系博主删除。