Creating tables in MATLAB is a straightforward process, enabling you to present data in an organized and easily understandable format. Tables are essential for data analysis, visualization, and reporting. In this guide, we'll walk you through the steps to create and manipulate tables in MATLAB.
![Créer une TABLE DES MATIÈRES automatique [Cours WORD] + Numérotation des titres + STYLES](https://i.pinimg.com/originals/3a/17/5f/3a175f694e47b4503e3485794f7597a9.jpg)
Before we dive into the details, ensure you have the latest version of MATLAB installed. If not, you can download it from the official MathWorks website and follow the installation instructions.

Creating a Table
MATLAB provides several ways to create tables. We'll explore two common methods: using arrays and using data stored in variables.

First, let's create a table using an array. An array is a multi-dimensional matrix containing elements of the same data type. To create a table, you can use the 'table' function, which converts an array into a table.
Using Arrays

To create a table using an array, follow these steps:
1. Define an array with your data. For example:
data = [1 2 3; 4 5 6; 7 8 9];
2. Convert the array into a table using the 'table' function:

myTable = table(data);
3. Display the table using the 'disp' function:
disp(myTable)
Using Data Stored in Variables
You can also create a table using data stored in variables. This method is useful when you have data scattered across multiple variables, and you want to combine them into a single table.

Let's create a table using variables. First, define your variables:
var1 = [1 2 3]; var2 = [4 5 6]; var3 = [7 8 9];
Next, create a table using the 'table' function and pass your variables as arguments:




















myTable = table(var1, var2, var3);
Finally, display the table:
disp(myTable)
Manipulating Tables
Once you've created a table, you can manipulate it using various functions and properties. MATLAB provides a wide range of tools for data manipulation, including sorting, filtering, and aggregating data.
Let's explore some common table manipulation techniques:
Sorting Tables
You can sort tables based on one or more variables using the 'sortrows' function. For example, to sort the 'myTable' created earlier in ascending order based on the second column:
sortedTable = sortrows(myTable, 2);
Filtering Tables
To filter data based on specific criteria, you can use logical indexing. For instance, to filter the 'myTable' and display only the rows where the third column is greater than 5:
filteredTable = myTable(myTable.Var3 > 5, :);
Aggregating Tables
You can aggregate data using functions like 'sum', 'mean', and 'median'. To calculate the sum of each column in the 'myTable', use the following code:
aggregatedTable = sum(myTable, 'omitnan');
In conclusion, creating and manipulating tables in MATLAB is a powerful way to organize, analyze, and present data. By mastering these techniques, you'll be well on your way to becoming a proficient MATLAB user. Happy coding!