graph.m
上传用户:m_sun_001
上传日期:2014-07-30
资源大小:1115k
文件大小:4k
源码类别:

matlab例程

开发平台:

Matlab

  1. % Program 6-5
  2. % graph.m
  3. %
  4. % The function of drawing the graph of simulation result.
  5. %
  6. % Input argument
  7. %   filename : name of the file which simulation result was stored.
  8. %
  9. % Output argument
  10. %   nothing
  11. %
  12. % Programmed by M.Okita
  13. % Checked by H.Harada
  14. %
  15. function graph(filename)
  16. mtitle1 = {'Throughput of Pure ALOHA system'        ...     % definition of the title
  17.            'Throughput of Slotted ALOHA system'     ...
  18.            'Throughput of np CSMA system'           ...
  19.            'Throughput of Slotted np ISMA system'   ...
  20.           };
  21. mtitle2 = {'Average Delay time of Pure ALOHA system'    ... % definition of the title
  22.            'Average Delay time of Slotted ALOHA system' ...
  23.            'Average Delay time of np CSMA system'       ...
  24.            'Average Delay time of Slotted ISMA system'  ...
  25.           };
  26. fid      = fopen(filename,'r');
  27. nul      = fscanf(fid,'%s',2);
  28. protocol = fscanf(fid,'%d',1);
  29. nul      = fscanf(fid,'%s',2);
  30. caputre  = fscanf(fid,'%d',1);
  31. nul      = fscanf(fid,'%s',2);
  32. dtime    = fscanf(fid,'%f',1);
  33. nul      = fscanf(fid,'%s',2);
  34. brate    = fscanf(fid,'%d',1);
  35. nul      = fscanf(fid,'%s',2);
  36. srate    = fscanf(fid,'%d',1);
  37. nul      = fscanf(fid,'%s',2);
  38. plen     = fscanf(fid,'%d',1);
  39. nul      = fscanf(fid,'%s',1);
  40. mnum     = fscanf(fid,'%d',1);
  41. nul      = fscanf(fid,'%s',2);
  42. mcn      = fscanf(fid,'%f',1);
  43. nul      = fscanf(fid,'%s',2);
  44. tcn      = fscanf(fid,'%f',1);
  45. nul      = fscanf(fid,'%s',2);
  46. spend    = fscanf(fid,'%d',1);
  47. idx = 0;
  48. while 1
  49.     data0 = fscanf(fid,'%f',1);
  50.     data1 = fscanf(fid,'%f',1);
  51.     data2 = fscanf(fid,'%f',1);
  52.     data3 = fscanf(fid,'%f',1);
  53.     data4 = fscanf(fid,'%f',1);
  54.     data5 = fscanf(fid,'%f',1);
  55.     data6 = fscanf(fid,'%f',1);
  56.     
  57.     if feof(fid) == 1                                           % eof
  58.         break
  59.     end
  60.     
  61.     idx = idx + 1;
  62.     
  63.     tg(idx) = data0;                                            % offered traffic
  64.     g(idx)  = data3 / data1;                                    % actual offered traffic
  65.     s(idx)  = data2 / data1;                                    % actual throughput
  66.     w(idx)  = data4 / spend * srate / plen;                     % average delay
  67. end
  68. fclose(fid);
  69. ts = theorys(protocol,g,dtime);                                 % calculation of the throughput
  70. if protocol < 3                                                 % Pure ALOHA & Slotted ALOHA
  71.     plot(g,s,'bo:',g,ts,'r-');                                  % normal graph
  72.     legend('result','theory',0);                                % legend
  73. else                                                            % np-CSMA & Slotted np-ISMA
  74.     semilogx(g,s,'bo:',g,ts,'r-');                              % semi log graph
  75.     if protocol == 3                                            % legend
  76.         legend(strcat('result (a=',num2str(dtime),')'),'theory',0);
  77.     else
  78.         legend(strcat('result (d=',num2str(dtime),')'),'theory',0);
  79.     end
  80. end
  81. title(char(mtitle1(protocol)),'FontSize',16);                   % title
  82. xlabel('Traffic(Simulation result)','FontSize',14);             % x axis label
  83. ylabel('Throughput','FontSize',14);                             % y axis label
  84. figure(2);                                                      % preparation of the new graph windos
  85. if protocol < 3                                                 % Pure ALOHA & Slotted ALOHA
  86.     plot(g,w,'bo:');                                            % normal graph
  87.     legend('result');                                           % legend
  88. else                                                            % np-CSMA & Slotted np-ISMA
  89.     semilogx(g,w,'bo:');                                        % semi log graph
  90.     if protocol == 3                                            % legend
  91.         legend(strcat('result (a=',num2str(dtime),')'),0);
  92.     else
  93.         legend(strcat('result (d=',num2str(dtime),')'),0);
  94.     end
  95. end
  96. title(char(mtitle2(protocol)),'FontSize',16);                   % title
  97. xlabel('Traffic(Simulation result)','FontSize',14);             % x axis label
  98. ylabel('Average Delay time(packet)','FontSize',14);             % y axis label
  99.  
  100. %%%%%%%%%%%%%%%%%%%%%% end of file %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%