S = table2struct(T)converts the table,T, to a structure array,S。每个变量Tbecomes a field inS。IfTis anm-by-ntable, thenSis am-by-1 structure array withnfields.
S = table2struct(T,'ToScalar',true)converts the table,T, to a scalar structureS。每个变量Tbecomes a field inS。IfTis am-by-ntable, thenShasnfields, each of which hasmrows.
T=5×3 tableGender Age BloodPressure ______ ___ _____________ Smith M 38 124 93 Johnson M 43 109 77 Williams F 38 125 83 Jones F 40 117 75 Brown F 49 122 80
ConvertTto a scalar structure.
S = table2struct(T,'ToScalar',真正的)
S =struct with fields:Gender: [5x1 categorical] Age: [5x1 double] BloodPressure: [5x2 double]
Add a field for the row names from the table.
S.RowNames = T.Properties.RowNames
S =struct with fields:Gender: [5x1 categorical] Age: [5x1 double] BloodPressure: [5x2 double] RowNames: {5x1 cell}
IfSis a nonscalar structure, use[S.RowNames] = T.Properties.RowNames{:}to include a field with the row names from the table.
IfThas variables whose names are not valid MATLAB®identifiers, thentable2structmodifies them to create valid field names, primarily by removing spaces and replacing non-ASCII characters with underscores.
Extended Capabilities
C/C++ Code Generation Generate C and C++ code using MATLAB® Coder™.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.