Skip to content
MATLAB

Struct Arrays and Tables

Work with struct arrays and modern table data type.

By EZ4Code Team
tablestructdata

Code

% Table (modern tabular data)
T = table([1;2;3], {'A';'B';'C'}, [90;85;92], ...
  'VariableNames', {'ID', 'Name', 'Score'});

% Access
T.Name          % column as cell array
T.Score(1)      % first row of Score
T.Score > 85    % logical index
T(T.Score > 85, :)  % filter rows

% Add column
T.Grade = {'A'; 'B'; 'A'};

% Summary
summary(T)

% Group operations
G = groupsummary(T, 'Grade', 'mean', 'Score');
% Grade  GroupCount  mean_Score
%  A     2           91
%  B     1           85

Explanation

Tables are the modern way to handle tabular data — like a dataframe in pandas. Use dot notation for column access and logical indexing for filtering. groupsummary performs grouped aggregations (like SQL GROUP BY). Prefer tables over structs for datasets with consistent columns.

More MATLAB Snippets