MatLab Analysis: Twenty20 Worldcup

MatLab Analysis: Twenty20 Worldcup

This is a simple Analysis on MatLab to visualize the data of a Twenty20 Wordcup match.
mic-1-1

In this tutorial i have used Matlab to plot the statistics of a T20 worldcup match played between australia and west indies. Matlab provides a wide array of plotting commands and options to represent any kind of statistical data. The data can be displayed in many formats like graphs, bar charts, pie charts,etc.

I have taken the data from cricinfo.com website then i have written a matlab m-file to produce the different plots. The data is written in to an excel file and is accessed by Matlab thorough the xlsread command:

The Bar Graph

mic-1-1

The second plot is Bar-chart representing the runs aganist the overs and fall of wickets for both the teams.The Bar in red represents the first team(West Indies) and the Bar in blue represents the second team(Australia).

The data inside the excel sheet is given in the form of runs per over for each over for both the teams. As this is a twenty20 Match there are only 20 overs. The excel file also contains information about the fall of wickets for each team representing the number of wickets down for the particular over.

This information is accessed through matlab and is processed to obtain the manipulated data which is required for plotting the graphs. The fall of wickets are also plotted in the same bar-graph represented as colored circles on the bars of the respective teams. This is done by plotting the overs where there is a wicket fall on the x-axis and the runs scored in that over are plotted on the y-axis.

All these functions are written into a Matlab GUI file.

The Line Chart

mic-1-1

The aim of this line chart is to give an idea of the rate of change of runs against overs.

In the first plot the scores of each team are plotted against overs. It also represents the fall of wickets for each team. To achieve this I have created a Matlab M-file and gave the necessary instructions to generate the plot according to the data that has been fed into it. Here the runs in the excel file are given as runs in the overs basis, so a function is written to make the data cumulative (i.e the total runs until that over) , these points are plotted in the y-axes with overs in the x-axis. Then these points are joined to produce a graph. The same is done for the other team as well.

The wickets are plotted in the same way as they are plotter for the bar-graph.

The Program

%-----------------------------------------------------------------
%    Title: Cricket Analysis
%   Author: Aditya Reddy P
%      Ver: 1.0
%     Date: May 22,2010
%      Rev:
%-----------------------------------------------------------------

% --- Executes on button press in plot.
function plot_Callback(hObject, eventdata, handles)

hold off;

Scores=xlsread('matlab.xls','b4:u5');
WicketsAus = xlsread('matlab.xls','b9:t9');  % Fall of wickets - Aus
WicketsWI = xlsread('matlab.xls','b10:t10'); % Fall of wickets - WI

WicketOversAus = GetWicketOvers(WicketsAus);
WicketOversWI = GetWicketOvers(WicketsWI);

bar(Scores','grouped');            %Plots Scores
xlabel('Overs');                   %Graph X-label
ylabel('Runs');                    %Graph Y-label
title('ICC World Twenty20 2010');  %Graph Title
legend('Aus','WI');                %Graph Legend

hold on;
grid on;

plot(WicketOversWI+.1,Scores(2,WicketOversWI)+.5,'ro','LineWidth',2,'MarkerSize',10);
plot(WicketOversAus-.15,Scores(1,WicketOversAus)+.5,'bo','LineWidth',2,'MarkerSize',10);

%-----------------------------------------------------------------

% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)

hold off
Scores=xlsread('matlab.xls','b4:u5')    % Read Both Scores from XL file
WicketsAus = xlsread('matlab.xls','b9:t9');   % Fall of wickets - Aus
WicketsWI = xlsread('matlab.xls','b10:t10');  % Fall of wickets - WI

WicketOversAus = GetWicketOvers(WicketsAus);
WicketOversWI = GetWicketOvers(WicketsWI);

ScoresAus = Scores(1,:);  % Cumulative Scores of Aus
for i=2:length(ScoresAus)
    ScoresAus(i) = ScoresAus(i) + ScoresAus(i-1);
end
ScoresWI = Scores(2,:);   % Cumulative Scores of WI
for i=2:length(ScoresWI)
    ScoresWI(i) = ScoresWI(i) + ScoresWI(i-1);
end

OversAus = [1:length(ScoresAus)];
OversWI = [1:length(ScoresWI)];

axis tight;
plot(OversAus,ScoresAus,'r',OversWI,ScoresWI,'LineWidth',2); % Plots Scores
xlabel('Overs');                      % Graph X-label
ylabel('Runs');                       % Graph Y-label
title('ICC World Twenty20 2010');     % Graph Title
legend('Aus','WI', 2);                % Graph Legend

hold on;
grid on;

plot(WicketOversWI,ScoresAus(WicketOversWI),'ro','LineWidth',2,'MarkerSize',10);
plot(WicketOversAus,ScoresWI(WicketOversAus),'bo','LineWidth',2,'MarkerSize',10);

%-----------------------------------------------------------------

% --- Picks Wickets with respect to overs
function WicketOvers = GetWicketOvers(Wickets)

WicketOvers = [];
if(Wickets(1)==1)
    WicketOvers = [1];
end

for i=2:length(Wickets)
    if(Wickets(i) ~= Wickets(i-1))
        WicketOvers = [WicketOvers i];
    end
end

%-----------------------------------------------------------------

Similar topics you might like…

Share this Post and become one of us...