How to Plot Excel Data in MATLAB

Cody Schneider8 min read

Getting your data from an Excel spreadsheet into a MATLAB plot doesn’t have to feel like a complex coding exercise. If you have experiment results, business metrics, or any dataset organized in Excel, MATLAB can transform it into insightful visualizations quickly. This guide will walk you through the entire process, covering the best methods for importing your data and creating clean, professional plots - no advanced programming degree required.

GraphedGraphed

Build AI Agents for Marketing

Build virtual employees that run your go to market. Connect your data sources, deploy autonomous agents, and grow your company.

Watch Graphed demo video

Before You Import: Prepping Your Excel Data

A little bit of preparation in your Excel file can save you a lot of trouble later. Before you even open MATLAB, make sure your data is structured in a way that’s easy to read and import. Think of it as setting the foundation before building the house.

1. Keep It Clean and Tidy ✨

The number one rule is to have a clean, tabular format. This means:

  • One Header Row: Your first row should contain clear, simple headers for each column (e.g., "Time_Seconds," "Temperature_C," "Pressure_kPa"). Avoid spaces or special characters in headers if you can, use underscores instead.
  • No Merged Cells: Merged cells are great for human-readable reports, but they confuse programmatic importers. Make sure every single row and column has its own distinct cell.
  • Consistent Data Types: Ensure each column contains only one type of data. The "Temperature_C" column should only have numbers, and the "Date" column should only have dates. Mixed data types (like text saying "N/A" in a numeric column) can cause import errors.

Example of Good vs. Bad Formatting:

A well-structured file looks like this:

An import-unfriendly file looks like this:

| ACME Sensor Readings (October 26th) // Merged Title Cell | |-------------------------------------| | | | Timestamp | Sensor | Reading | | 2023-10-26 10:00 | A | 98.6 | | // Empty Row for spacing | | | | 2023-10-26 10:01 | B | Error | // Text in a number column

The first example is machine-readable and primed for import, while the second will likely cause errors or require manual cleanup in MATLAB.

2. Use Separate Sheets for Separate Datasets

If you have different sets of data (e.g., Q1 sales and Q2 sales), place them on separate sheets in your Excel workbook. This makes it easier to tell MATLAB exactly which data you want to import, preventing any accidental mix-ups.

Method 1: Using MATLAB's Built-In Import Tool

For one-off analyses or if you're just getting started, MATLAB’s graphical Import Tool is by far the easiest method. It provides a visual interface to select and import your data without writing much code.

Free PDF · the crash course

AI Agents for Marketing Crash Course

Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.

Step-by-Step Guide to the Import Tool:

1. Open the Tool

In the MATLAB main window, navigate to the HOME tab. In the VARIABLE section, you’ll see an icon labeled Import Data. Click it.

2. Select Your File

A file browser window will pop up. Locate your prepared .xlsx or .csv file and double-click it.

3. Define Your Data Range

The Import Tool will open, showing a preview of your spreadsheet. MATLAB is usually pretty smart about automatically selecting the main data table, but you can adjust the selection by dragging the corners of the blue box. In the ribbon at the top, pay attention to the Output Type. For most datasets, importing as a "Table" is the best option. A MATLAB table is very similar to an Excel table - it keeps your columns organized with their headers.

4. Import the Data

Once you are happy with the selection and output type, click the green checkmark labeled Import Selection. MATLAB will now create a variable in your Workspace (usually named after your filename, e.g., sensordata).

Plotting Your Imported Data

Now for the fun part! Let's say your Excel file had two columns, Time and Temperature, and the variable created in your workspace is named sensordata.

You can access the columns of a table using dot notation: tableName.columnName.

To create a simple line plot, you just need one line of code:

plot(sensordata.Time, sensordata.Temperature)

Type that into the Command Window and hit Enter. A new Figure window will pop up with your plot. Of course, a basic plot isn't very helpful without context. Let's add some labels and a title:

% Plot the data
figure, % Using `figure` opens a new window, which is good practice
plot(sensordata.Time, sensordata.Temperature, '-o'), % '-o' creates a line with markers

% Add descriptive labels and a title
title('Engine Temperature Over Time'),
xlabel('Time (in hours)'),
ylabel('Temperature (Celsius)'),
grid on, % Adds a grid for easier reading

This code block generates a clean, well-labeled graph that clearly communicates the relationship between your two variables.

Method 2: For Automation with the readtable() Function

Using the Import Tool is great for quick tasks, but if you need to run the same import and plotting process regularly, you'll want a more automated approach. The readtable() function is perfect for this. It lets you import Excel data directly within a script, allowing you to re-run your entire analysis with a single click.

GraphedGraphed

Build AI Agents for Marketing

Build virtual employees that run your go to market. Connect your data sources, deploy autonomous agents, and grow your company.

Watch Graphed demo video

How to Use readtable()

The basic syntax is incredibly simple. To import the entire first sheet of an Excel file into a table variable, you just need:

myData = readtable('yourfilename.xlsx'),

MATLAB will automatically use the first row as headers and infer the data types for each column. The variable myData will now be a table in your workspace, just like with the Import Tool.

Adding More Specificity

Sometimes you need more control. readtable() has optional arguments to handle more complex files:

  • To specify a sheet: If your data is on a sheet named "Q3_Data," you can tell MATLAB to grab it from there.
quarterlyData = readtable('sales_report.xlsx', 'Sheet', 'Q3_Data'),
  • To specify a range: If you only need a portion of the sheet, say cells A1 through C51.
campaignData = readtable('marketing.xlsx', 'Range', 'A1:C51'),

Full Plotting Example with readtable()

Let's tie it all together. Imagine you have a script that needs to analyze weekly sensor data from a file named log_latest.xlsx. Here’s how you could automate the import and plotting process:

% ---- Script to Analyze Weekly Sensor Data ----

% Step 1: Import the data from the 'SensorReadings' sheet
disp('Importing data...'),
sensorData = readtable('log_latest.xlsx', 'Sheet', 'SensorReadings'),
disp('Import complete.'),

% Step 2: Create a plot of Pressure vs. Vibration
figure,
plot(sensorData.Pressure, sensorData.Vibration, '.'), %'.' creates a scatter plot

% Step 3: Add context to the plot
title('Vibration Levels Relative to System Pressure'),
xlabel('Pressure (PSI)'),
ylabel('Vibration (mm/s)'),
legend('Sensor Readings'),
grid on,

disp('Plot generated successfully!'),

By saving this code in a .m file, you can simply run it every week when you drop a new log_latest.xlsx file into your folder. This programmatic approach is efficient, repeatable, and less prone to user error.

Making Your MATLAB Plots Look Professional

Once the data is plotted, take a few extra moments to make your visualizations clear and compelling. First impressions matter, even with data graphs.

Free PDF · the crash course

AI Agents for Marketing Crash Course

Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.

Customizing Colors, Lines, and Markers

You can easily change the look of your plot directly in the plot() function. It takes an optional third argument that specifies the line style, marker symbol, and color.

For example:

  • '--r' creates a red dashed line.
  • ':gs' creates a green dotted line with square markers at each data point.
  • 'b*' creates blue star markers with no connecting line.
% Plot Temperature with a red dashed line and circle markers
plot(timeData, tempData, '--ro'),

% Add a second dataset for Humidity on the same plot
hold on, % This command tells MATLAB to add the next plot to the same figure
plot(timeData, humidityData, '-.bs'),
hold off, % Release the hold

legend('Temperature', 'Humidity'), % Update legend to describe both datasets

Plotting Multiple Graphs in One Figure

If you want to compare different datasets side-by-side instead of layering them, use the subplot() function. It divides your figure window into a grid.

subplot(rows, cols, index) selects which grid cell to draw the next plot in.

figure,

% Create a 2x1 grid, and select the first position
subplot(2, 1, 1),
plot(time, temperature, '-r'),
title('Temperature'),

% Select the second position
subplot(2, 1, 2),
plot(time, pressure, '--b'),
title('Pressure'),

This creates a tall figure with the temperature plot on top and the pressure plot on the bottom, making it easy to see correlations over the same time period.

Final Thoughts

Whether you use the visual Import Tool for a quick look or the readtable() function for building repeatable scripts, moving data from Excel to MATLAB is a straightforward process. The key is starting with clean, well-organized data and then using MATLAB's powerful plotting functions to add titles, labels, and customizations that turn raw numbers into a clear story.

While MATLAB is an unbeatable tool for in-depth engineering and scientific analysis, sometimes you just need quick answers from business data without writing any code. At Graphed, we've focused on automating that kind of reporting. Instead of digging through spreadsheets or writing scripts, you connect your business apps (like Shopify, Google Analytics, or Salesforce) and just ask for the visuals you need in plain English. For situations where tracking marketing performance or sales funnels is the goal, platforms like Graphed are built to deliver instant, real-time dashboards without the setup and technical overhead.

Related Articles