⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mote_state.m

📁 用于matlab仿真程序。可用在无线传感器网络中。
💻 M
字号:
function [sys,x0,str,ts]=mote_state(t,x,u,flag,init_state);%ANIMATION S-function for animating the motion of the motes.switch flag, case 0,  [sys,x0,str,ts]= mdlInitializeSizes; case 2,  sys = mdlUpdate(t,x,u); case 3,  sys = mdlOutputs(t,x,u); case 65, case 9,  sys = mdlTerminate(t,x,u); otherwise  error(['Unhandled flag = ',num2str(flag)]);end%=============================================================================% mdlInitializeSizes%=============================================================================function [sys,x0,str,ts]=mdlInitializeSizesglobal stateglobal axes_handleglobal state_textts = 0.1;if length(state) >0% Read parametersnumMotes = length(state);% Initialize the figure for use with this simulationxmax=30;ymax=700;figure_handle = figure(3);clf(figure_handle);set(figure_handle,'Renderer','OpenGL');set(figure_handle,'Position',[550 400 500 400])axes_handle = axes;title('MOTE STATUS');grid(axes_handle, 'on')set(axes_handle,'Xlim',[-xmax xmax],'Ylim',[-ymax ymax],'nextplot','add');set(axes_handle,'XTickLabel',[]);set(axes_handle,'YTickLabel',[]);set(axes_handle, 'XTick', [-xmax+0.5 0 xmax-0.5],'XColor', [1 1 1]);set(axes_handle, 'YTick', [-ymax+3 0 ymax-3],'YColor', [1 1 1]);set(axes_handle,'Color',[1 1 0.3]);moteTitle = text(-xmax+1, ymax-60, 'Player Status:');set(moteTitle, 'FontSize', 24);for i=1:numMotes  state_text(i) = text(-xmax+1, ymax-(100*i)-100, ['Mote ' num2str(i) ...		    ' State '	state{i}]);  set(state_text(i), 'FontSize', 18, 'Color', [0 0 0]);endendset(axes_handle,'Color',[1 1 0.3]);sizes = simsizes;sizes.NumContStates  = 0;sizes.NumDiscStates  = 0;          sizes.NumOutputs     = 0;sizes.NumInputs      = 0; % x and y sizes.DirFeedthrough = 0;sizes.NumSampleTimes = 1;   sys = simsizes(sizes);x0  = [];str = [];ts  = [ts 0]; % Hybrid block%=============================================================================% mdlOutputs%=============================================================================function [sys]=mdlOutputs(t,x,u)sys = [];%=============================================================================% mdlUpdate%=============================================================================function [sys]=mdlUpdate(t,x,u)global stateglobal axes_handleglobal state_textnumMotes = length(state);xmax=30;ymax=700;%update graphicsif length(state) > 0  for i=1:numMotes    set(state_text(i), 'String', '');    set(state_text(i), 'String', ['Mote ' num2str(i) ' State	' state{i}]);  endenddrawnow;sys=[];%=============================================================================% mdlTerminate% Perform any end of simulation tasks.%=============================================================================function sys=mdlTerminate(t,x,u)closesys = [];      

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -