Structure Arrays in MATLAB

MATLAB Illustration

Notes on Structure Arrays in MATLAB

A structure array (struct array) is a data type where each element is a structure with named fields, ideal for organizing heterogeneous data (e.g., records with mixed types).

Key Features

  • Fields accessed via dot notation: struct.field or struct(index).field.
  • All elements must have the same fields.
  • Can be 1D (row/column) or multidimensional.

Basic Operations

  1. Create Single Struct:
    matlab
    MATLAB
    s.name = 'Alice';
    s.age = 30;
    s.height = 1.65;
  2. Build Struct Array:
    matlab
    MATLAB
    data(1) = s;
    % First element data(2).name = 'Bob';
    data(2).age = 45;
    data(2).height = 1.80;
  3. Efficient Creation:
    matlab
    MATLAB
    names = {'Alice', 'Bob', 'Charlie'};
    ages = [30; 45; 28];
    data = struct('name', names, 'age', ages, 'height', {1.65, 1.80, 1.70});
  4. Access Data:
    matlab
    MATLAB
    data(1).name         % 'Alice' [data.age]           % [30 45 28] data([1 3]).height   % Heights of 1st and 3rd
  5. Useful Functions:
    • fieldnames(data) → list fields
    • rmfield(data, 'age') → remove field
    • struct2table(data) → convert to table (preferred for tabular data)
    • isfield(data, 'name') → check field existence

Tips

  • Use tables instead for large datasets (better performance and display).
  • Great for grouped data like experiments, configurations, or object collections.

Need Expert Guidance with MATLAB or Simulink?

Our 500+ PhD engineers provide verified MATLAB code, custom Simulink models, and 1-on-1 tutoring with Turnitin plagiarism reports.

Verified Feedback

What Engineering Students Say

Real feedback from students across top engineering universities worldwide.

Verified Student

“I got full marks on my MATLAB DSP assignment! The filter design code was completely vectorized, the frequency response plots were exact, and the delivery was 8 hours before my deadline. Highly recommended!”

AS

Aditi Sharma

IIT Bombay • Signal Processing Coursework
Verified Student

“Our Simulink EV powertrain model had severe algebraic loop and solver errors. The MATLABSolutions team fixed the solver configuration in 4 hours and provided an annotated scope diagram. Lifesaver for my final year!”

JM

John M.

Monash University, Australia • Simulink Dynamic Model
Technical Knowledge Base

Latest MATLAB Guides & Tutorials

Explore deep-dive technical articles written by our engineering team to master complex MATLAB & Simulink topics.

MATLAB Guide 5 Min Read

AI-Tuned Adaptive PI and Fractional-Order Control for Hybrid Microgrid Inverters in MATLAB

Modern renewable energy grids face a major operational hurdle: the loss of rotational inertia. As solar photovoltaics, wind energy, and battery energy storage s...

MATLAB Guide 5 Min Read

Solving 6-DOF Aircraft & Quadrotor Flight Dynamics in MATLAB: ode45 vs. ode15s and Quaternion Kinematics

Simulating a 6-Degree-of-Freedom (6-DOF) flight vehicle in MATLAB looks straightforward on paper. You set up Newton-Euler equations of motion, calculate aerodynamic...