Matlab

How to Access Data in Tables in MATLAB?

A table is a container for variables that hold data that is organized in columns. Each table variable has the same number of rows having different data sizes and data types. Table variables have names, just like structure fields. We can retrieve the table data utilizing various methods. This article will explore how to access data in the table in MATLAB.

Methods to Access the Table Data in MATLAB?

In MATLAB, there are three methods to access data in a table that are listed below:

Let’s explain these methods in detail to access table data in MATLAB.

1: Access Data in the Table Using Smooth Parenthesis

Accessing table data using smooth parenthesis () is a widely used method in MATLAB. This method allows us to access the rows and variables of the specified table and returns another table having the selected rows and variables of the input table. For example,

Name = {'Rivest';'Shamir';'Adleman';'Thomas';'Stewart'};

Marks = [900;1070;875;987;750];

Percentage = [82; 97; 80; 90; 68];

Grade = {'A';'A+';'A';'A+';'B'};

T = table(Name,Marks,Percentage, Grade);

T(1:3,[2,4])

2: Access Data in Table Using Dot Notation

Another method used for accessing the data in the table is using dot notation (.). This method is used for accessing the data stored in the table variables and it returns an array containing the variable’s contents. For example,

Name = {'Rivest';'Shamir';'Adleman';'Thomas';'Stewart'};

Marks = [900;1070;875;987;750];

Percentage = [82; 97; 80; 90; 68];

Grade = {'A';'A+';'A';'A+';'B'};

T = table(Name,Marks,Percentage, Grade);

T.Name(1:4)

3: Access Data in the Table Using Curly Braces

In MATLAB, we can also access the data in Tables using curly braces {}. This method is used for accessing the selected data from the rows and table variables by returning an array concatenated from the accessed data from the selected rows and variables. For example,

Name = {'Rivest';'Shamir';'Adleman';'Thomas';'Stewart'};

Marks = [900;1070;875;987;750];

Percentage = [82; 97; 80; 90; 68];

Grade = {'A';'A+';'A';'A+';'B'};

T = table(Name,Marks,Percentage, Grade);

T{:, 2:3}

Conclusion


A table is a container for variables that hold data that is organized in columns. Each table variable has the same number of rows having different data sizes and data types. We can access the data in the table using various methods including smooth parenthesis, dot notation, and curly braces. This tutorial taught us how to access table data in MATLAB using different methods.

About the author

Komal Batool Batool

I am passionate to research technologies and new ideas and that has brought me here to write for the LinuxHint. My major focus is to write on programming languages and computer science related topics.