Computing with Descriptive Statistics - MATLAB & Simulink (2024)

Computing with Descriptive Statistics

If you need more advanced statistics features, you might want to use the Statistics and Machine Learning Toolbox™ software.

Functions for Calculating Descriptive Statistics

Use the following MATLAB® functions to calculate the descriptive statistics for your data.

Note

For matrix data, descriptive statistics for each column are calculated independently.

Statistics Function Summary

Function

Description

max

Maximum value

mean

Average or mean value

median

Median value

min

Smallest value

mode

Most frequent value

std

Standard deviation

var

Variance, which measures the spread or dispersion of the values

The following examples apply MATLAB functions to calculate descriptive statistics:

  • Example 1 — Calculating Maximum, Mean, and Standard Deviation

  • Example 2 — Subtracting the Mean

Example 1 — Calculating Maximum, Mean, and Standard Deviation

This example shows how to use MATLAB functions to calculate the maximum, mean, and standard deviation values for a 24-by-3 matrix called count. MATLAB computes these statistics independently for each column in the matrix.

% Load the sample dataload count.dat% Find the maximum value in each columnmx = max(count)% Calculate the mean of each columnmu = mean(count)% Calculate the standard deviation of each columnsigma = std(count)

The results are

mx = 114 145 257mu = 32.0000 46.5417 65.5833sigma = 25.3703 41.4057 68.0281

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:

[mx,indx] = max(count)

These results are

mx = 114 145 257indx = 20 20 20

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, 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:

min(count(:))ans = 7

Example 2 — Subtracting the Mean

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

% Get the size of the count matrix[n,p] = size(count)% Compute the mean of each columnmu = mean(count)% Create a matrix of mean values by% replicating the mu vector for n rowsMeanMat = repmat(mu,n,1)% Subtract the column mean from each element% in that columnx = count - MeanMat

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 Remove Linear Trends from Timetable Data.

Example: Using MATLAB Data Statistics

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:

Note

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

Calculating and Plotting Descriptive Statistics

  1. Load and plot the data:

    load count.dat[n,p] = size(count);% Define the x-valuest = 1:n;% Plot the data and annotate the graphplot(t,count)legend('Station 1','Station 2','Station 3','Location','northwest')xlabel('Time')ylabel('Vehicle Count')

    Computing with Descriptive Statistics- MATLAB & Simulink (1)

    Note

    The legend contains the name of each data set, as specified by the legend function: Station 1, Station 2, and Station 3. A data set refers to each column of data in the array you plotted. If you do not name the data sets, default names are assigned: data1, data2, and so on.

  2. In the Figure window, select Tools > Data Statistics.

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

    Note

    The Data Statistics dialog box displays a range, which is the difference between the minimum and maximum values in the selected data set. The dialog box does not display the range on the plot.

  3. Select a different data set in the Data Statistics for list: Station 2.

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

  4. 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.

    Computing with Descriptive Statistics- MATLAB & Simulink (2)

    This plots a horizontal line to represent the mean of Station 2 and updates the legend to include this statistic.

    Computing with Descriptive Statistics- MATLAB & Simulink (3)

Formatting Data Statistics on Plots

The Data Statistics dialog box uses colors and line styles to distinguish statistics from the data on the plot. This portion of the example shows how to customize the display of descriptive statistics on a plot, such as the color, line width, line style, or marker.

Note

Do not edit display properties of statistics until you finish plotting all the statistics with the data. If you add or remove statistics after editing plot properties, the changes to plot properties are lost.

To modify the display of data statistics on a plot:

  1. In the MATLAB Figure window, click the Computing with Descriptive Statistics- MATLAB & Simulink (4) (Edit Plot) button in the toolbar.

    This step enables plot editing.

  2. Double-click the statistic on the plot for which you want to edit display properties. For example, double-click the horizontal line representing the mean of Station 2.

    This step opens the Property Inspector, where you can modify the appearance of the line used to represent this statistic.

    Computing with Descriptive Statistics- MATLAB & Simulink (5)

  3. In the Property Inspector window, specify the line and marker styles, sizes, and colors.

    Tip

    Alternatively, right-click the statistic on the plot, and select an option from the shortcut menu.

Saving Statistics to the MATLAB Workspace

Perform these steps to save the statistics to the MATLAB workspace.

Note

When your plot contains multiple data sets, save statistics for each data set individually. To display statistics for a different data set, select it from the Data Statistics for list in the Data Statistics dialog box.

  1. In the Data Statistics dialog box, click the Save to Workspace button.

  2. In the Save Statistics to Workspace dialog box, select options to save statistics for either X data, Y data, or both. Then, enter the corresponding variable names.

    In this example, save only the Y data. Enter the variable name as Loc2countstats.

    Computing with Descriptive Statistics- MATLAB & Simulink (6)

  3. Click OK.

    This step saves the descriptive statistics to a structure. The new variable is added to the MATLAB workspace.

To view the new structure variable, type the variable name at the MATLAB prompt:

Loc2countstats
Loc2countstats = struct with fields: min: 9 max: 145 mean: 46.5417 median: 36 mode: 9 std: 41.4057 range: 136

Generating Code Files

This portion of the example shows how to generate a file containing MATLAB code that reproduces the format of the plot and the plotted statistics with new data. Generating a code file is not available in MATLAB Online™.

  1. In the Figure window, select File > Generate Code.

    This step creates a function code file and displays it in the MATLAB Editor.

  2. Change the name of the function on the first line of the file from createfigure to something more specific, like countplot. Save the file to your current folder with the file name countplot.m.

  3. Generate some new, random count data:

    rng('default')randcount = 300*rand(24,3);
  4. Reproduce the plot with the new data and the recomputed statistics:

    countplot(t,randcount)

    Computing with Descriptive Statistics- MATLAB & Simulink (7)

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Computing with Descriptive Statistics- MATLAB & Simulink (8)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

Computing with Descriptive Statistics
- MATLAB & Simulink (2024)
Top Articles
Meritain Prior Authorization List
Movies produced by DreamWorks Animation — The Movie Database (TMDB)
Funny Roblox Id Codes 2023
Golden Abyss - Chapter 5 - Lunar_Angel
Www.paystubportal.com/7-11 Login
Joi Databas
DPhil Research - List of thesis titles
Shs Games 1V1 Lol
Evil Dead Rise Showtimes Near Massena Movieplex
Steamy Afternoon With Handsome Fernando
Which aspects are important in sales |#1 Prospection
Detroit Lions 50 50
18443168434
Newgate Honda
Zürich Stadion Letzigrund detailed interactive seating plan with seat & row numbers | Sitzplan Saalplan with Sitzplatz & Reihen Nummerierung
Grace Caroline Deepfake
978-0137606801
Nwi Arrests Lake County
Justified Official Series Trailer
London Ups Store
Committees Of Correspondence | Encyclopedia.com
Pizza Hut In Dinuba
Jinx Chapter 24: Release Date, Spoilers & Where To Read - OtakuKart
How Much You Should Be Tipping For Beauty Services - American Beauty Institute
Free Online Games on CrazyGames | Play Now!
Sizewise Stat Login
VERHUURD: Barentszstraat 12 in 'S-Gravenhage 2518 XG: Woonhuis.
Jet Ski Rental Conneaut Lake Pa
Unforeseen Drama: The Tower of Terror’s Mysterious Closure at Walt Disney World
Ups Print Store Near Me
C&T Wok Menu - Morrisville, NC Restaurant
How Taraswrld Leaks Exposed the Dark Side of TikTok Fame
University Of Michigan Paging System
Random Bibleizer
10 Best Places to Go and Things to Know for a Trip to the Hickory M...
Black Lion Backpack And Glider Voucher
Gopher Carts Pensacola Beach
Duke University Transcript Request
Lincoln Financial Field, section 110, row 4, home of Philadelphia Eagles, Temple Owls, page 1
Jambus - Definition, Beispiele, Merkmale, Wirkung
Ark Unlock All Skins Command
Craigslist Red Wing Mn
D3 Boards
Jail View Sumter
Nancy Pazelt Obituary
Birmingham City Schools Clever Login
Thotsbook Com
Funkin' on the Heights
Vci Classified Paducah
Www Pig11 Net
Ty Glass Sentenced
Latest Posts
Article information

Author: Golda Nolan II

Last Updated:

Views: 5832

Rating: 4.8 / 5 (78 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Golda Nolan II

Birthday: 1998-05-14

Address: Suite 369 9754 Roberts Pines, West Benitaburgh, NM 69180-7958

Phone: +522993866487

Job: Sales Executive

Hobby: Worldbuilding, Shopping, Quilting, Cooking, Homebrewing, Leather crafting, Pet

Introduction: My name is Golda Nolan II, I am a thoughtful, clever, cute, jolly, brave, powerful, splendid person who loves writing and wants to share my knowledge and understanding with you.