Use the dot notation to specify the fields of a struct array. Each element in the array is of class
% Struct array with fields 'name' and 'sex' patients(1).name = 'Peter Pan'; patients(1).sex = 'M'; whos patients;
Name Size Bytes Class Attributes patients 1x1 372 struct
Struct arrays can be of any size and have the following properties:
- All structs in the array have the same number of fields
- All structs have the same field names
- Fields of the same name in different structs can contain different types or sizes of data
I recommend the following books to learn more on struct arrays in MATLAB:
This book was the winner of a 2017 Textbook Excellence Award. Struct arrays, cell arrays, and other data types, are explained clearly in the eighth chapter.
MATLAB for Engineers (5th Edition)
This excellent book is especially oriented to engineers and scientists who want to learn MATLAB programming. Chapter 11 explains excellently struct arrays, cell arrays, and character arrays, among other data types.
I also recommend the other tutorials in this series.
- Struct Arrays in MATLAB
- How to Create Struct Arrays in MATLAB
- How to Read Values From a Struct Array in MATLAB
- How to Write Values to a Struct Array in MATLAB
- How to Delete Items From a Struct Array in MATLAB
- How to Remove Fields From a Struct Array in MATLAB
- How to Check if a Struct Array Has a Field in MATLAB
- How to Check if a Variable Holds a Struct Array in MATLAB
- How to Get the Field Names of a Struct Array in MATLAB
I hope you have understood what struct arrays are in MATLAB. The source code developed in this tutorial is available at this page.