Methods to Access the Table Data in MATLAB?
In MATLAB, there are three methods to access data in a table that are listed below:
- Access data in the table Using Smooth Parenthesis
- Access data in the table Using Dot Notation
- Access data in the table Using Curly Braces
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,
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,
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,
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.