【游戏】基于 matlab GUI lanchester作战模拟设计【含Matlab源码 426期】
【摘要】
一、获取代码方式
获取代码方式1: 完整代码已上传我的资源:【游戏】基于 matlab GUI lanchester作战模拟设计【含Matlab源码 426期】
获取代码方式2: 通过订阅紫极神光博客...
一、获取代码方式
获取代码方式1:
完整代码已上传我的资源:【游戏】基于 matlab GUI lanchester作战模拟设计【含Matlab源码 426期】
获取代码方式2:
通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。
备注:
订阅紫极神光博客付费专栏,可免费获得1份代码(有效期为订阅日起,三天内有效);
二、部分源代码
function varargout = lcst(varargin)
% LCST M-file for lcst.fig
% LCST, by itself, creates a new LCST or raises the existing
% singleton*.
%
% H = LCST returns the handle to a new LCST or the handle to
% the existing singleton*.
%
% LCST('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in LCST.M with the given input arguments.
%
% LCST('Property','Value',...) creates a new LCST or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before lcst_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to lcst_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 lcst
% Last Modified by GUIDE v2.5 26-Oct-2008 20:07:52
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @lcst_OpeningFcn, ...
'gui_OutputFcn', @lcst_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 lcst is made visible.
function lcst_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 lcst (see VARARGIN)
axes(handles.axes2);
[x1,map]=imread('1.jpg');
[x2,map]=imread('2.jpg');
x3=imread('3.jpg');
x4=imread('4.jpg');
x5=imread('5.jpg');
x6=imread('6.jpg');
x7=imread('7.jpg');
x8=imread('8.jpg');x9=imread('9.jpg');x10=imread('10.jpg');x11=imread('11.jpg');
M(1)=im2frame(x1,map);
M(2)=im2frame(x2,map);M(3)=im2frame(x3,map);
M(4)=im2frame(x4,map);M(5)=im2frame(x5,map);
M(6)=im2frame(x6,map);M(7)=im2frame(x7,map);
M(8)=im2frame(x8,map);M(9)=im2frame(x9,map);
M(10)=im2frame(x10,map);
M(11)=im2frame(x11,map);
movie(M,1000,3)
% Choose default command line output for lcst
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% This sets up the initial plot - only do when we are invisible
% so window can get raised using lcst.
% UIWAIT makes lcst wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = lcst_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 simulation.
function simulation_Callback(hObject, eventdata, handles)
% hObject handle to simulation (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes1);
cla;
x0=str2double(get(handles.red1,'String'));
a=str2double(get(handles.red2,'String'));
y0=str2double(get(handles.blue1,'String'));
b=str2double(get(handles.blue2,'String'));
% for k=1:100
% t(k)=et/100*k
% x(k)=x0-a*t(k);
% y(k)=y0-b*t(k);
% end
popup_sel_index = get(handles.popupmenu1, 'Value');%根据不同的定律进行计算
switch popup_sel_index
case 1
if a*y0>b*x0
et=x0/a;
Rb=(a*y0-b*x0)/a;
Rr=0;
w='蓝方';
end
if a*y0<b*x0
et=y0/b;
Rr=(b*x0-a*y0)/b;
Rb=0;
w='红方';
end
if a*y0==b*x0
et=x0/a;
Rr=0;
Rb=0;
w='同归于尽';
end
set(handles.winp,'string',w);
set(handles.endt,'string',num2str(et));
set(handles.redr,'string',num2str(Rr));
set(handles.bluer,'string',num2str(Rb));
% if x(end)==0
plot([0,et],[x0,Rr],'r-');
hold on
plot([0,et],[y0,Rb],'b-');
hold off
grid on
grid minor
case 2
if a*y0^2>b*x0^2
w='蓝方';
Rb=sqrt(y0^2-(b/a)*x0^2)
Rr=0;
et=log((sqrt(b)*x0+sqrt(a)*y0)/(-sqrt(b)*x0+sqrt(a)*y0))/2/sqrt(a*b);
end
if a*y0^2<b*x0^2
w='红方';
Rr=sqrt(x0^2-(a/b)*y0^2)
Rb=0;
et=log((sqrt(b)*x0+sqrt(a)*y0)/(sqrt(b)*x0-sqrt(a)*y0))/2/sqrt(a*b);
end
set(handles.winp,'string',w);%显示计算结果
set(handles.endt,'string',num2str(et));
set(handles.redr,'string',num2str(Rr));
set(handles.bluer,'string',num2str(Rb));
%fh = @(x,y) a.*x.^2 - b.*y.^2 - a.*y0.^2+b.*x0.^2;
%ezplot(@(x,y)myfun(x,y,x0,a,y0,b),[0,x0]);
t=[0:0.1:et];
ab=sqrt(a*b);
x=x0*cosh(ab*t)-(sqrt(a/b)*y0)*sinh(ab*t);
y=y0*cosh(ab*t)-(sqrt(b/a)*x0)*sinh(ab*t);
plot(t,x,'r-');
hold on
plot(t,y,'b-');
hold off
grid minor
% bar(1:.5:10);
% case 4
% plot(membrane);
% case 5
% surf(peaks);
end
% --------------------------------------------------------------------
function FileMenu_Callback(hObject, eventdata, handles)
% hObject handle to FileMenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function OpenMenuItem_Callback(hObject, eventdata, handles)
% hObject handle to OpenMenuItem (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
file = uigetfile('*.fig');
if ~isequal(file, 0)
open(file);
end
% --------------------------------------------------------------------
function PrintMenuItem_Callback(hObject, eventdata, handles)
% hObject handle to PrintMenuItem (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
printdlg(handles.figure1)
% --------------------------------------------------------------------
function CloseMenuItem_Callback(hObject, eventdata, handles)
% hObject handle to CloseMenuItem (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
selection = questdlg(['Close ' get(handles.figure1,'Name') '?'],...
['Close ' get(handles.figure1,'Name') '...'],...
'Yes','No','Yes');
if strcmp(selection,'No')
return;
end
delete(handles.figure1)
% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if (double(get(hObject,'Value')==2))
set(handles.text6,'ForegroundColor','yellow');
end
% Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu1
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','blue');
end
set(hObject, 'String', {'lanchester线性律', 'lanchester平方律', });%选择菜单的设计
function red1_Callback(hObject, eventdata, handles)
% hObject handle to red1 (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 red1 as text
% str2double(get(hObject,'String')) returns contents of red1 as a double
% --- Executes during object creation, after setting all properties.
function red1_CreateFcn(hObject, eventdata, handles)
% hObject handle to red1 (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
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216
- 217
- 218
- 219
- 220
- 221
- 222
- 223
- 224
- 225
- 226
- 227
- 228
- 229
- 230
- 231
- 232
- 233
- 234
- 235
- 236
- 237
- 238
- 239
- 240
- 241
- 242
- 243
- 244
- 245
- 246
- 247
- 248
- 249
- 250
- 251
- 252
- 253
- 254
- 255
- 256
- 257
- 258
- 259
- 260
- 261
- 262
- 263
- 264
- 265
- 266
- 267
- 268
三、运行结果
四、matlab版本及参考文献
1 matlab版本
2014a
2 参考文献
[1] 包子阳,余继周,杨杉.智能优化算法及其MATLAB实例(第2版)[M].电子工业出版社,2016.
[2]张岩,吴水根.MATLAB优化算法源代码[M].清华大学出版社,2017.
文章来源: qq912100926.blog.csdn.net,作者:海神之光,版权归原作者所有,如需转载,请联系作者。
原文链接:qq912100926.blog.csdn.net/article/details/114259341
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)