Create a function called genStats that computes statistics f

Create a function called genStats that computes statistics for a set of experimental runs. The data are stored in an Excel file, and genStats will compute statistics, then write the data together with the statistics in another Excel file. Assume a format similar to The first row is a header row, and the first column a list of team names. There may be any number of teams and each team may have any number of trials, but you may assume that there will be at least one team and at least one trial per team. genStats will accept as input the name of the Excel file, and will produce no output. It will perform the following steps: Calculate the average score for each team (each row), and store it in a new column called Average to the right of the rightmost trial column. Calculate the deviation for each team, and store it in a new column called Deviation to the right of the Average column. Calculate the average of each trial (each column), as well as the average of averages and the average deviation, and store it beneath the bottom row of the data. The name of the bottom row (what goes in the Team column) is Total Average. Write the original data plus new data to an Excel file called Stats_ .xlsx. For instance, if the original file were called ScoreData.xlsx, the new file should be called Stats_ScoreData.xlsx.

Solution

The results are

To get the row numbers where the maximum data values occur in each data column, specify a second output parameter indx to return the row index. For example:

These results are

Here, the variable mx is a row vector that contains the maximum value in each of the three data columns. The variable indx contains the row indices in each column that correspond to the maximum values.

To find the minimum value in the entire count matrix, reshape this 24-by-3 matrix into a 72-by-1 column vector by using the syntax count(:). Then, to find the minimum value in the single column, use the following syntax:

Example 2 — Subtracting the Mean

Subtract the mean from each column of the matrix by using the following syntax:

Note:   Subtracting the mean from the data is also called detrending. For more information about removing the mean or the best-fit line from the data, see Detrending Data.

Example: Using MATLAB Data Statistics

The Data Statistics dialog box helps you calculate and plot descriptive statistics with the data. This example shows how to use MATLAB Data Statistics to calculate and plot statistics for a 24-by-3 matrix, called count. The data represents how many vehicles passed by traffic counting stations on three streets.

This section contains the following topics:

Calculating and Plotting Descriptive Statistics

Formatting Data Statistics on Plots

Saving Statistics to the MATLAB Workspace

Generating Code Files

Note:   MATLAB Data Statistics is available for 2-D plots only.

Calculating and Plotting Descriptive Statistics

Load and plot the data:

select Tools > Data Statistics .

The Data Statistics dialog box opens and displays descriptive statistics for the X- and Y-data of the Team 1 data set.

Select a different data set in the Statistics for list: Team 2.

This displays the statistics for the X and Y data of the Team 2 data set.

Select the check box for each statistic you want to display on the plot, and then click Save to workspace.

For example, to plot the mean of Station 2, select the mean check box in the Y column

Note:   Subtracting the mean from the data is also called detrending. For more information about removing the mean or the best-fit line from the data, see Detrending Data.

 Create a function called genStats that computes statistics for a set of experimental runs. The data are stored in an Excel file, and genStats will compute stat
 Create a function called genStats that computes statistics for a set of experimental runs. The data are stored in an Excel file, and genStats will compute stat

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site