标题:【求助】一个MATLAB代码的调试
只看楼主
naoxin
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-6-21
 问题点数:0 回复次数:0 
【求助】一个MATLAB代码的调试
function x=animation_data
% Animation definition for application FLOOD2D
%为FLOOD2D应用作动态定义

small=5; medium=20; large=50;

%                Event_name    Animated   Color/{on/off/toggle}    Size   
%               事件名称  动态      颜色/ (开启 /关闭/双态的)  大小
anim_def={...
        {'Init_Application',          0,        [0 0 0 ],         small}, ...
        {'Packet_Sent',               1,        [0 1 0 ],         small}, ...
        {'Packet_Received',           1,        [0 1 0 ],         small}, ...
        {'Collided_Packet_Received',  0,        [1 0 0 ],         small}, ...
        {'Clock_Tick',                0,        [0 0 0 ],         small}, ...
        {'Channel_Request',           0,        [0 0 0 ],         small}, ...
        {'Channel_Idle_Check',        1,        [1 0 0 ],         small}, ...
        {'Packet_Receive_Start',      0,        [0 1 0 ],         small}, ...
        {'Packet_Receive_End',        0,        [0 0 0 ],         small}, ...
        {'Packet_Transmit_Start',     1,        [1 0 0 ],         medium}, ...
        {'Packet_Transmit_End',       0,        [0 1 0 ],         small}
       };


for i=1:length(anim_def)
    a=anim_def{i};
    x(i)=struct('event', a{1}, 'animated', a{2}, 'color', a{3}, 'size', a{4});
end
if ID==1 % first node starts flood    %第一个节点开始泛洪
        Set_Clock(1000)
    end
    PrintMessage('i')
case 'Packet_Sent'
    PrintMessage('s')

case 'Packet_Received'
    % data.data            % message
    % data.signal_strength % received signal strength  %接收信号强度
    if memory.send
   S;     p=sim_params('get_app', 'P');
   S;     if isempty(p); p=.5; end
   S;     if rand<p
   S;         Send_Packet(radiostream(data.data, memory.signal_strength));
   S;     end
   S;     memory.send=0;
   S;     PrintMessage('r')

   S; end
case 'Collided_Packet_Received'
    % this is for debug purposes only
   
case 'Clock_Tick'
    Send_Packet(radiostream('Message for 00111 from Golomb', memory.signal_strength));

case 'GuiInfoRequest'
   disp(sprintf('Memory Dump of mote ID# %d:\n',ID)); disp(memory)
   
case 'Application_Stopped'
   % this event is called when simulation is stopped/suspended
   
case 'Application_Finished'
   % this event is called when simulation is finished
   
otherwise
    error(['Bad event name for application: ' event])
end

%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%                                          %%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%         APPLICATION ENDS                 %%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%               HERE                       %%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%                                          %%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
S; %%%%%%%%%%%%%%%%%%%%%% housekeeping %%%%%%%%%%%%%%%%%%%%%%%%%%%
S;        app_data{ix}=memory;
S; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%                           %%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%        COMMANDS           %%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%                           %%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function b=Send_Packet(data);
global ID t
radio=prowler('GetRadioName');
b=feval(radio, 'Send_Packet', ID, data, t);

function b=Set_Clock(alarm_time);
global ID
prowler('InsertEvents2Q', make_event(alarm_time, 'Clock_Tick', ID));

function PrintMessage(msg)
global ID
prowler('TextMessage', ID, msg)

function LED(msg)
global ID
prowler('LED', ID, msg)
function varargout=info
% FLOOD application information file

title1='Application FLOOD1D';
str1={  'This application illustrates the simple flooding algorithm.'; ...
        '';...
        'The sender mote transmits a message. Each mote receiving the';...
        'message retransmits it with probability p.' ;...
        'The value of p can be set in the ''Application Parameters''';...
        'window. The default value is p=0.5';...
        '';...
        'If p is too low, the flood dies out before every mote could';...
        'receive the message. If p it too high, the message is';...
        'retransmitted several times after every mote have received it,' ;...
        'thus causing an unnecessarily high settling time.';...
        '';...
        'The optimal value of p highly depends on topology.';...
        '';...
        'You can change the topology by editing the file FLOOD1D_TOPOLOGY.';...
        '';...
        'See also FLOOD2D.';...
        ''};
if nargout==0
    helpwin({ title1, str1}, 'Application Info')
else
    varargout={ title1, str1};
end
function param=params;
% Application parameter definition file


param(1).name='P';             param(1).default=0.5;

function [topology,mote_IDs]=topology(varargin);
% Topology information for application FLOOD1D

Nx=10; Ny=1; % number of points on the grid

ix=1;t=[];
distx=1;
disty=5;
X=1:distx:(Nx-1)*distx+1;
Y=1:disty:(Ny-1)*disty+1;
for i=X
    for j=Y
        t=[t; i,j];
    end
end
topology=t;
mote_IDs=1:Nx*Ny;  
我是个初学者不会挑这个程序的错误,希望哪位大侠帮下忙!急!
这个程序是分为5个小部分
是不是要一部分一部分运行啊
搜索更多相关主题的帖子: MATLAB 代码 调试 
2008-06-21 23:46



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-220467-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.108430 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved