ans=5×4 table
Gender Age Smoker BloodPressure
Male 38 true 124 93
Male 43 false 109 77
Female 38 false 125 83
Female 40 false 117 75
Female 49 false 122 80
The table displays in a tabular format with the variable names at the top.
Each variable in a table is a single data type. If you add a new row to the table,
MATLAB® forces consistency of the data type between the new data and the
corresponding table variables. For example, if you try to add information for a new
patient where the first column contains the patient's age instead of gender, as in the
expression T(end+1,:) = {37,{'Female'},true,[130 84]}, then you receive the
error:
Invalid RHS for assignment to a categorical array.
The error occurs because MATLAB® cannot assign numeric data, 37 , to the categorical
array, Gender.
For comparison of tables with structures, consider the structure array, StructArray,
that is equivalent to the table, T.
StructArray = table2struct(T)
StructArray = 100x1 struct array with fields:
Gender
Age
Smoker
BloodPressure
Structure arrays organize records using named fields. Each field's value can have a
different data type or size. Now, display the named fields for the first element of
StructArray.
StructArray(1)
ans = struct with fields:
Gender: Male
Advantages of Using Tables