Self-Definition Function For Plotting Simulation Results
Directory
一、Parameters Setting
POINT_NUMBER = 10;
LINE_INTERVAL = 50;
FONT_SIZE = 8.0;
FIGURE_SIZE = [7 7 7 7];
COORDINATE_LIMITATION = [0, 1000, 0, 500] ; % [x_Starting, x_ending, y_Starting, y_ending]
FIGURE_RATIO = [0.065 0.10 0.85 0.85];
LINE_WIDTH = 1.5;
MARKER_SIZE = 5;
二、Self-definition Function
代码如下(示例):
function [ ] = plotSimulationResults( DataArray1,DataArray2,... %DataArray3,DataArray4,
POINT_NUMBER, LINE_INTERVAL,...
FONT_SIZE, FIGURE_SIZE, COORDINATE_LIMITATION, FIGURE_RATIO, LINE_WIDTH, MARKER_SIZE )
figure('Name','The compartion of xxx','color',[1 1 1]);
set(gca,'fontsize',FONT_SIZE); %set the font size
set(gcf,'Units','centimeter','Position',FIGURE_SIZE); % FIGURE_SIZE = [8, 8, 8, 8]
axis(COORDINATE_LIMITATION); %[x_begining, x_ending, y_begining, y_ending]
set(gca,'Position',FIGURE_RATIO); % for removing white margin
grid;
xlabel('x (times)');
ylabel('y (%)');
hold on;
RoundNumber = length(DataArray1);
DataArray1 = [0,DataArray1];
DataArray2 = [0,DataArray2];
% DataArray3 = [0,DataArray3];
% DataArray4 = [0,DataArray4];
pointInterval = RoundNumber./POINT_NUMBER;
pointBeginPoint = 0;
lineBeginPoint = 0;
for index = pointBeginPoint:pointInterval:RoundNumber
plot( index, DataArray1( index+1 ),'Color','blue','Marker','x','MarkerFaceColor','blue','MarkerSize',MARKER_SIZE);
plot( index, DataArray2( index+1 ),'Color','red','Marker','<','MarkerFaceColor','red','MarkerSize',MARKER_SIZE);
% plot( index, DataArray3( index+1 ),'Color','green','Marker','d','MarkerFaceColor','green','MarkerSize',MARKER_SIZE);
% plot( index, DataArray4( index+1 ),'Color','black','Marker','o','MarkerFaceColor','black','MarkerSize',MARKER_SIZE);
hold on;
end
plot( lineBeginPoint:LINE_INTERVAL:RoundNumber,DataArray1(1:LINE_INTERVAL:(RoundNumber+1)),'Color','blue ','LineStyle','-','LineWidth',LINE_WIDTH); % The LineStyle parameter where you can set to '-', '--', ':', or ':.'
hold on;
plot( lineBeginPoint:LINE_INTERVAL:RoundNumber,CentralizedCoverageRadioArray(1:LINE_INTERVAL:(RoundNumber+1)),'Color','red ','LineStyle','-','LineWidth',LINE_WIDTH);
hold on;
% plot( lineBeginPoint:lineInterval:RoundNumber,DataArray3(1:lineInterval:(RoundNumber+1)),'Color','green ','LineStyle','-','LineWidth',LINE_WIDTH);
% hold on;
% plot( lineBeginPoint:lineInterval:RoundNumber,DataArray4(1:lineInterval:(RoundNumber+1)),'Color','black ','LineStyle','-','LineWidth',LINE_WIDTH);
% hold on;
legend_ = legend('Algorithm1','Algorithm2','Algorithm3','Algorithm4'); % set the name for the legend
set(legend_,'Location','NorthWest'); % set the location of the legend,and the paramecter where you can set to NorthWest, NorthEast, SouthWest, or SouthEast.
end