Skip to content
MATLAB

结构体数组与 Table

使用结构体数组和现代 table 数据类型。

#table#struct#data

Code

matlab
% 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