Exploring Table Plotting in MATLAB

MATLAB, a high-level programming language used for technical computing, is popular among computer scientists, engineers, analysts, and researchers. Its extensive features are incredibly useful in hand …

Updated November 22, 2023


Hey! If you love Computer Vision and AI, let's connect on Twitter or LinkedIn. I talk about this stuff all the time!

MATLAB, a high-level programming language used for technical computing, is popular among computer scientists, engineers, analysts, and researchers. Its extensive features are incredibly useful in handling complex mathematical and algorithmic tasks. One of its many capabilities involves data visualization, such as plotting tables that display numerical results in organized formats. In this article, we will delve into the details on how to create effective table plots using MATLAB’s graphical user interface (GUI) and scripting environment. We will also provide useful code snippets and examples along the way, helping you to understand the significance of plotting tables and how they can be valuable in analyzing data efficiently.

Table Plots in MATLAB: Overview and Benefits

A table plot, often known as a “table view” or “data grid,” is a type of graphical representation that displays numerical results in an organized manner. Unlike the traditional scatter plots or line graphs, which are used for depicting numeric data as points or lines respectively, table plots are useful when working with tabular or multidimensional data. These types of data often have multiple variables and values, making it challenging to represent them in a more conventional graph format.

There are several benefits associated with using MATLAB’s table plotting functionality:

  1. Ease of Data Comprehension: Table plots make it simple for users to quickly understand the relationship between various variables and their corresponding values. This is especially useful when dealing with large datasets or when visualizing data from different dimensions.

  2. Enhanced Clarity in Comparing Variables: As table plots display all relevant information neatly within a single view, it becomes easier to compare and contrast different variables and the relationships among them.

  3. Efficient Data Analysis: MATLAB’s table plotting features enable you to identify patterns, outliers, or any significant trends in your data more easily. This makes it an essential tool for data analysts and scientists who need to spot important insights.

Creating Table Plots with MATLAB

To generate a table plot in MATLAB, we can utilize either its GUI or script-based approach. The process involves the following steps:

  1. Importing and Organizing Data: Begin by importing your data into MATLAB from various sources such as CSV files, Excel sheets, or other compatible formats. Make sure to organize the data appropriately in multidimensional arrays or matrices, where rows represent observations and columns display the variables being examined.

  2. Setting Up Table Plotting Options: Choose the properties of your table plot, including how rows and columns should be displayed. You can opt for either a ‘RowLabels’ or ‘ColumnLabels’ arrangement to determine which variable is represented along the X-axis (rows) and Y-axis (columns). Additionally, specify other visual attributes like font size, line styles, and markers for the data points within each cell of your table plot.

  3. Creating a Table Plot using MATLAB GUI: Launch MATLAB’s graphical user interface and navigate to the “Plot” tab. In the menu, choose ‘Table’, followed by ‘New Table’. This will create an empty table plot window in which you can begin adding your data.

  4. Adding Data to Your Table Plot: Import the previously prepared multidimensional arrays containing your numerical data into MATLAB using the ‘Data’ command. Once imported, assign these variables to your table view by selecting the appropriate input variables under the ‘Values’ section of the table plot window. Alternatively, you can drag and drop your array variables directly onto the table plot window from the workspace.

  5. Customizing Your Table Plot: To further enhance the visual appearance of your table plots, modify various attributes like font size, line styles, marker shapes, and cell coloring. These customizations will make it easier to read and comprehend the numerical information being displayed.

  6. Saving Your Table Plots for Future Use: To preserve your table plots, you can save them as figures using MATLAB’s ‘Save As’ command or as image files in various formats such as PNG, TIFF, JPG, or PDF by selecting the appropriate format under the ‘Format’ dropdown menu. This enables easy sharing and distribution of the plot with others for further analysis or discussion.

Sample Code Snippets for Table Plotting in MATLAB:

To demonstrate the process of creating table plots using both GUI and scripting modes, let us consider a simple dataset containing sales figures for three products: A, B, and C. These are measured across five time periods (Weeks 1 to 5). Here’s the example data:

% Create dummy product sales data
Sales_Data = [100 200 300; 80 170 360; 90 140 250];
Products = ["A", "B", "C"];
Weeks = ["Week 1", "Week 2", "Week 3", "Week 4", "Week 5"];

Now, we will plot this data as a table with MATLAB’s GUI and scripting methods. Note that the code snippets below use the variable names ‘Sales_Data’, ‘Products’, ‘Weeks’, and other constants defined in the example dataset.

Table Plots using the MATLAB GUI:

% Using MATLAB's GUI to create a table plot of the given data
% Step 1: Create new Table
table_view = table(Sales_Data, 'VariableNames', {Products', 'Weeks'}, ...
                   'RowLabels', Weeks, 'ColumnLabels', Products);
% Step 2: Customize visual properties
table_view.PropertyEditor.TableViewOptions.CellColors = [0 1; 1 0; 1 0];
table_view.PropertyEditor.TableViewOptions.TextInteriorColor = 'white';
table_view.PropertyEditor.TableViewOptions.DataLabelPosition = 'insidecell';
% Step 3: Save the Table Plot as a figure
figure
plot(table_view)
saveas(gcf, 'Sales_Per_Product.png', 'PNG');

Table Plots using MATLAB Scripting:

% Creating a table plot of the given data using a script
% Step 1: Create table variables for rows and columns
RowLabels = Weeks;
ColumnLabels = Products;
RowData = Sales_Data;
ColumnData = CellArray(numel(Products), numel(Weeks));
for i = 1:numel(Products)
    ColumnData{i, :} = Sales_Data(:, i);
end
% Step 2: Define the table plot options
TableOptions = struct('RowLabels', RowLabels, 'ColumnLabels', ColumnLabels, ...
                     'RowData', RowData, 'ColumnData', ColumnData);
% Step 3: Create the table plot and visualize it with the given data
table_view = table(TableOptions);
plt = plot(table_view);
% Step 4: Save the Table Plot as a figure
figure
plot(table_view)
saveas(gcf, 'Sales_Per_Product.png', 'PNG');

In conclusion, MATLAB offers a user-friendly environment for creating table plots that effectively display multidimensional and complex data sets in an organized manner. By utilizing its GUI or scripting functionalities, you can visualize and analyze numerical data with ease while making meaningful observations regarding patterns, trends, and correlations within your datasets. These skills are beneficial across various domains such as scientific research, engineering analysis, and data-driven decision-making.