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

Physics-Informed Neural Networks (PINNs) for UAV Wind-Gust Rejection & Aerodynamic Modeling in MATLAB

Drones flying between city buildings, around offshore turbines, or over ridges run into sudden wind gusts and wake turbulence that linear controllers handle poorly. A tuned PID ...

MATLAB Guide 5 Min Read

Optimal Tuning of Fractional-Order PID (FOPID) Controllers Using Hybrid Beetle Swarm Optimization in MATLAB

Fractional-Order Proportional-Integral-Derivative (FOPID or PIλDμ) controllers expand classical three-term control by introducing non-intege...