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.
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

Reinforcement Learning for Microgrid Energy Management in MATLAB & Simulink

Operating a modern microgrid is an ongoing balancing act. Between changing solar output, shifting wind speeds, volatile electricity pricing, and unpredictable consumer demand, a...

MATLAB Guide 5 Min Read

Physics-Informed Neural Networks (PINNs) for Microgrid Dynamics and Power Flow in MATLAB

Modern microgrids operate with low physical inertia, rapid inverter switching dynamics, and intermittent renewable power generation. Simulating these systems requir...