Skip to content
MathWorks - Mobile View
  • Sign In to Your MathWorks AccountSe connecter
  • Access your MathWorks Account
    • Mon compte
    • Mon profil
    • Mes licences
    • Se déconnecter
  • Produits
  • Solutions
  • Le monde académique
  • Support
  • Communauté
  • Événements
  • Obtenir MATLAB
MathWorks
  • Produits
  • Solutions
  • Le monde académique
  • Support
  • Communauté
  • Événements
  • Obtenir MATLAB
  • Sign In to Your MathWorks AccountSe connecter
  • Access your MathWorks Account
    • Mon compte
    • Mon profil
    • Mes licences
    • Se déconnecter

Vidéos et webinars

  • MathWorks
  • Vidéos
  • Vidéos
  • Recherche
  • Vidéos
  • Recherche
  • Contacter l'équipe commerciale
  • Version d'essai
6:06 Video length is 6:06.
  • Description
  • Full Transcript
  • Related Resources

What are Tables and How are They Used in MATLAB

Table arrays store column-oriented or tabular data, such as columns from a text file or spreadsheet.  Tables store each piece of column-oriented data in a variable which may contain different types of data. Learn how to take advantage of MATLAB tools and functionalities to perform everything from high-level analysis to complex functions on external table data such as Excel spreadsheets or tabular data.

Welcome to using tables in MATLAB! In this video, we’ll define what a table is in MATLAB, how to import external table data into MATLAB from programs like Excel, and how to perform basic functions on the table using MATLAB.

Table arrays store column-oriented or tabular data, such as columns from a text file or spreadsheet.  Tables store each piece of column-oriented data in a variable which may contain different types of data.  For instance, tables may contain numerical data, alphanumerical or text strings, or categorical data.  In this video, we will focus on working with numerical and alphanumerical data.  

Tables are often found in formats such as spreadsheets or delimited-value files.  You’re probably familiar with tables in programs like Excel.  You can import, analyze, and extract table data in MATLAB without having to manually recreate a table from Excel.  Let’s look at an example.

Here, we have an Excel table with the average summer highs at MathWorks locations in North America.  You’ll see we have three different data types in the table: text strings, categorical, and numerical.  For this video, we will focus on working with alphanumeric and numerical data.

Let’s get this table imported into MATLAB.  

To import a table into MATLAB, click on “Import Data” in the top toolbar.

Navigate to where your table is located, select it, and click Open.

You’ll see that MATLAB is able to determine the table elements.  First, you’ll see the name of the table at the top based on the file name.  Second, you’ll see the table headers; these are called variable names in MATLAB.  You can adjust the row of variable names using the drop-down menu at the top.  Third, you’ll see the data types.  In this example, you’ll see locations represented as text data, time zones represented as categorical data, and temperatures represented as numerical data. 

If you want to change any data in the table, you can do so by double-clicking the corresponding cell .

If you want to change the data type of any variable, use the drop-down menu.

Once you are satisfied with the data you want to import, click Import Selection.  In MATLAB, you’ll see the table in the Workspace.

At any point, you can make changes to the table, by double-clicking on the table in the workspace to open the variable editor, selecting any of the cells, and making any necessary changes to its value.  You’ll notice that as you make any changes, it will display programmatically in the command window.

By right-clicking on aAny variable, you can sort the data as if you were in Excel, delete data, or export data into a separate table.  You can also add metadata to each variable.  

To obtain a high-level overview of table data, you can use the summary function to view a quick analysis of the table data by column.  For instance, we see there are three MathWorks locations in the Pacific Standard Time Zone, and the median average temperature in July of the MathWorks North America locations is 82 degrees.

You can do more than just analyze data using tables in MATLAB.  

You can use dot-indexing to perform functions on a single variable.  For example, if we want to find the mean (average) temperature of the North America locations in August, it can be easily done using the mean function.

Let’s assign meanaugtemp to equal the mean of August temperatures.  And you’ll see the average temperature in August of the North American locations is 81.5 degrees.

What if you want to focus on a specific variable of the table?  You can use curly braces ({}) to extract data from one variable into a single array.  For instance, let’s extract the July temperatures for further analysis.  We can extract the variable with the following syntax: SampleTable{1:5, ‘July’}

You can also concatenate the data further by extracting multiple variables.  If we wanted to extract July and August temperatures for further analysis, we would use the following syntax: SampleTable{1:5, ‘July’ ‘August’}.  This extracts the data into a single array.

If you want to extract specific variables of a table into a new table, you can do so with the following syntax using paranthesis: define the new table name = SampleTable(1:5, ‘July’ ‘August’) 

You can even add variables to a table using functions.  For instance, if we wanted to calculate the mean of each location’s summer temperature, we would have to add each average temperature – June, July, and August – and then divide by three.  In MATLAB, we would use the following syntax: SampleTable.meantemp = (SampleTable.June + SampleTable.July + SampleTable.August)/3.  We’ll see that it adds the new variable to the end of the table and performs the calculation.

There are many other functions you can perform on tables variables.  The MATLAB help documentation on tables and variables has lots of information, examples, and live scripts you can download to practice.  To access the help documentation, click on the question mark icon in the top right.

In this video, we covered how to define a table and the types of data tables contain, how to perform an analysis of the data, and how to perform basic functions.  Take advantage of MATLAB tools and functionalities to perform everything from high-level analysis to complex functions on external table data such as Excel spreadsheets or tabular data.  If you’re ready to take the next step using tables in MATLAB, we have more videos on importing Excel spreadsheets, performing complex table functions, and using categorical data in tables.  

Related Products

  • MATLAB

Learn More

Creating a Table in MATLAB (Documentation)
New MATLAB Features in Release 2013b

3 Ways to Speed Up Model Predictive Controllers

Read white paper

A Practical Guide to Deep Learning: From Data to Deployment

Read ebook

Bridging Wireless Communications Design and Testing with MATLAB

Read white paper

Deep Learning and Traditional Machine Learning: Choosing the Right Approach

Read ebook

Hardware-in-the-Loop Testing for Power Electronics Control Design

Read white paper

Predictive Maintenance with MATLAB

Read ebook

Electric Vehicle Modeling and Simulation - Architecture to Deployment : Webinar Series

Register for Free

How much do you know about power conversion control?

Start quiz

Feedback

Featured Product

MATLAB

  • Request Trial
  • Get Pricing

Up Next:

1:43
Setting the Initial Working Folder in MATLAB to be the Last...

Related Videos:

5:03
Grouping Operations for Tables and Arrays
31:29
MATLAB: Tips and Tricks
39:07
MATLAB Meets MINDSTORMS: How to Control LEGO NXT Robots...
4:15
How to Label a Series of Points on a Plot in MATLAB

View more related videos

MathWorks - Domain Selector

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

  • Switzerland (English)
  • Switzerland (Deutsch)
  • Switzerland (Français)
  • 中国 (简体中文)
  • 中国 (English)

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

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

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)
  • 中国
    • 简体中文Chinese
    • English
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

  • Contacter l'équipe commerciale
  • Version d'essai

MathWorks

Accelerating the pace of engineering and science

MathWorks est le leader mondial des logiciels de calcul mathématique pour les ingénieurs et les scientifiques.

Découvrir…

Découvrir les produits

  • MATLAB
  • Simulink
  • Version étudiante
  • Support Hardware
  • File Exchange

Essayer ou acheter

  • Téléchargements
  • Version d'essai
  • Contacter un commercial
  • Tarifs et licences
  • Comment acheter

Se former

  • Documentation
  • Tutoriels
  • Exemples
  • Vidéos et webinars
  • Formation

Obtenir de l'aide

  • Aide à l'installation
  • MATLAB Answers
  • Services de consulting
  • Centre de gestion des licences
  • Contacter le support technique

La société

  • Offres d'emploi
  • Actualités
  • Mission sociale
  • Témoignages clients
  • La société
  • Select a Web Site United States
  • Trust Center
  • Marques déposées
  • Charte de confidentialité
  • Lutte anti-piratage
  • État des applications

© 1994-2022 The MathWorks, Inc.

  • Facebook
  • Twitter
  • Instagram
  • YouTube
  • LinkedIn
  • RSS

Rejoignez la conversation