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 85Explanation
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
Matrix Creation and Operations
Create and operate on matrices in MATLAB.
2D Plotting
Create line plots with labels, legends, and styling.
Functions and Scripts
Define functions in separate files or at end of scripts.
Cell Arrays and Structs
Heterogeneous data containers in MATLAB.
File I/O
Read and write .mat, .csv, and text files.
ODE Solvers
Solve ordinary differential equations with ode45.