www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/ConvertNonscalarStructureArraytoTableExample.m

    %% Convert Nonscalar Structure Array to Table  

%% 
% Create a nonscalar structure array, |S|. 
S(1,1).Name = 'CLARK';
S(1,1).Gender = 'M';
S(1,1).SystolicBP = 124;
S(1,1).DiastolicBP = 93;

S(2,1).Name = 'BROWN';
S(2,1).Gender = 'F';
S(2,1).SystolicBP = 122;
S(2,1).DiastolicBP = 80;

S(3,1).Name = 'MARTIN';
S(3,1).Gender = 'M';
S(3,1).SystolicBP = 130;
S(3,1).DiastolicBP = 92;

S 

%%
% |S| is a 3-by-1 structure array with four fields.  

%% 
% Convert the structure array to a table. 
T = struct2table(S) 

%%
% The structure field names in |S| become the variable names in the output
% table. The size of |T| is 3-by-4.