www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/ConvertTabletoScalarStructureExample.m
%% Convert Table to Scalar Structure % Create a table, |T|, with five rows and three variables. T = table(categorical({'M';'M';'F';'F';'F'}),[38;43;38;40;49],... [124 93;109 77; 125 83; 117 75; 122 80],... 'VariableNames',{'Gender' 'Age' 'BloodPressure'}) %% % Convert |T| to a scalar structure. S = table2struct(T,'ToScalar',true) %% % The data in the fields of the scalar structure are 5-by-1, corresponding % to the five rows in the table |T|. %% % Display the data for the field |BloodPressure|. S.BloodPressure %% % The structure field |BloodPressure| contains all of the data that was % in the variable of the same name from table |T|.