Fiveable

🫠Intro to Engineering Unit 8 Review

QR code for Intro to Engineering practice questions

8.4 Data analysis and visualization techniques

8.4 Data analysis and visualization techniques

Written by the Fiveable Content Team • Last updated August 2025
Written by the Fiveable Content Team • Last updated August 2025
🫠Intro to Engineering
Unit & Topic Study Guides

Data analysis and visualization are core skills in engineering. They let you make sense of raw experimental data and communicate your findings to others. MATLAB provides a solid set of tools for this entire workflow, from importing messy data files to producing publication-ready plots.

This section covers data manipulation, statistical analysis, visualization techniques, and interactive GUI design in MATLAB.

Data Manipulation in MATLAB

Importing and Organizing Data

MATLAB has several functions for loading data from external files into your workspace:

  • importdata handles many common formats automatically
  • xlsread reads Excel spreadsheets
  • csvread reads comma-separated value files

Once your data is loaded, the table data type is especially useful. Tables let you store different types of data (numbers, text, dates) together with named column headers, which makes your code much more readable than working with raw numeric arrays.

To prepare datasets for analysis, you'll frequently need to index, slice, and reshape arrays:

  • Slicing with the colon operator: array(1:5, :) selects the first 5 rows across all columns
  • Reshaping dimensions: reshape(A, 3, []) rearranges elements into a matrix with 3 rows (MATLAB figures out the number of columns automatically)

Data Cleaning and Preprocessing

Real engineering data is rarely perfect. Before you analyze anything, you need to clean it up.

Missing values can be filled using fillmissing, which supports several strategies:

  • fillmissing(data, 'constant', 0) replaces missing entries with a fixed value
  • fillmissing(data, 'linear') interpolates linearly between known points

Outliers can be detected with isoutlier, which flags data points that fall outside expected bounds (for example, beyond 3 standard deviations from the mean, or using median absolute deviation).

Normalization scales your variables so they're comparable. This matters when variables have very different units or magnitudes:

  • Z-score normalization: normalize(data, 'zscore') centers data at mean 0 with standard deviation 1
  • Min-max scaling: normalize(data, 'range') scales values to the [0, 1] interval

Basic Statistical Analysis

MATLAB has built-in functions for common descriptive statistics:

  • mean([1 2 3 4 5]) returns 3 (the average)
  • median([1 2 3 4 5]) returns 3 (the middle value)
  • std(data) computes the standard deviation (how spread out values are)
  • var(data) computes the variance (the square of the standard deviation)

For more complex methods like clustering, classification, or advanced regression, MATLAB's Statistics and Machine Learning Toolbox extends these capabilities significantly.

Statistical Analysis of Engineering Data

Hypothesis Testing and Regression

Hypothesis testing lets you determine whether differences in your experimental results are statistically significant or just due to random variation.

  • Two-sample t-test: [h, p] = ttest2(group1, group2) compares the means of two groups. The output h tells you whether to reject the null hypothesis (1 = reject, 0 = fail to reject), and p gives the p-value.
  • anova1 compares means across more than two groups
  • chi2gof tests whether data fits an expected distribution

Regression analysis models the relationship between variables, which is essential for predicting behavior from experimental data:

  • Linear regression: mdl = fitlm(X, y) fits a straight-line model to your data
  • Non-linear regression: mdl = fitnlm(X, y, model) fits a model you define (useful when the relationship between variables isn't linear)
Importing and Organizing Data, Functions Palette/Programming/Numeric/Data Manipulation - LabVIEW Wiki

Time Series and Dimensionality Reduction

When your data changes over time, time series analysis helps you find patterns:

  • autocorr(data) shows how correlated a signal is with delayed versions of itself, which reveals periodic behavior
  • crosscorr(data1, data2) measures the correlation between two different time series

Principal Component Analysis (PCA) reduces the number of variables in a dataset while preserving the most important variation. This is helpful when you have many measured variables but suspect only a few underlying factors drive the behavior.

  • [coeff, score, latent] = pca(data) performs PCA. The latent output tells you how much variance each principal component explains.

Advanced Statistical Techniques

  • Bayesian optimization uses bayesopt to intelligently search for optimal model parameters by building a probabilistic model of the objective function
  • Reliability analysis assesses how likely a system is to fail over time:
    • wblfit fits a Weibull distribution to failure data, which is commonly used in engineering reliability studies
    • Monte Carlo simulations generate thousands of random samples to estimate system reliability when analytical solutions aren't practical

Advanced Visualization Techniques

3D Plotting and Animation

MATLAB can produce three-dimensional plots for visualizing relationships among three variables:

  • plot3(x, y, z) draws a 3D line through your data points
  • surf(X, Y, Z) creates a colored surface plot (great for showing how a response varies across two input parameters)
  • contour3(X, Y, Z) draws 3D contour lines on a surface

To create animations that show how data evolves over time:

  1. Set up a loop that updates your plot at each time step
  2. Capture each frame with F(i) = getframe(gcf)
  3. Play the animation with movie(F)

Plot Customization and Enhancement

MATLAB gives you fine control over how plots look:

  • Lighting: lighting gouraud applies smooth shading to 3D surfaces
  • Transparency: alpha(0.5) makes a surface 50% transparent, useful for overlapping objects
  • Camera angle: view(45, 30) sets the azimuth to 45° and elevation to 30°

For combining multiple views of your data in one figure:

  • subplot(2,2,1) divides the figure into a 2×2 grid and selects the first position
  • hold on lets you overlay multiple plots on the same axes (call hold off when you're done)
Importing and Organizing Data, Frontiers | CoSMoMVPA: Multi-Modal Multivariate Pattern Analysis of Neuroimaging Data in Matlab ...

Color Mapping and Output

Color maps translate numeric values into colors, which helps viewers quickly grasp quantitative differences across a surface or image.

  • colormap(jet) applies a built-in colormap (you can also pass a custom n×3n \times 3 matrix of RGB values)
  • caxis([min max]) sets the range of data values that map to the full color scale

When exporting figures for reports or presentations, format and resolution matter:

  • Vector graphics (scalable, no pixelation): print('-dpdf', 'filename.pdf')
  • High-resolution raster: print('-dpng', '-r300', 'filename.png') exports at 300 dpi

Interactive User Interface Design

GUI Development Approaches

MATLAB offers two main ways to build graphical user interfaces:

App Designer is the visual, drag-and-drop approach. You pick components (buttons, sliders, dropdown menus, plot axes) from a library, arrange them on a canvas, and wire up their behavior through a property inspector. This is the fastest way to get a working GUI.

Programmatic GUIs give you more control by building everything in code:

  • fig = figure('Name', 'My GUI') creates the main window
  • uicontrol('Style', 'pushbutton', 'String', 'Click me') adds a button

Event-Driven Programming and Interactivity

GUIs work through event-driven programming: instead of running code top-to-bottom, the program waits for user actions (clicks, slider drags) and responds by executing callback functions.

  • Assign a callback to a button: set(button, 'Callback', @buttonCallback)
  • For custom events, use listeners: addlistener(obj, 'EventName', @eventCallback)

A common pattern is updating a plot in real time based on user input. Inside your callback function, you'd call something like plot(axes, newData) to refresh the visualization whenever the user changes a parameter.

Layout Management and Deployment

Organizing components neatly requires layout managers:

  • g = uigridlayout(fig, [3 2]) creates a 3-row by 2-column grid
  • You then place components into specific grid cells, which keeps the layout clean as the window resizes

Once your GUI is finished, you can distribute it to people who don't have MATLAB installed:

  1. Use MATLAB Compiler to package your app: mcc -m myApp.m
  2. This produces a standalone executable that runs with the free MATLAB Runtime
  3. Share the executable along with the Runtime installer