create a table in matlab

To create a table in MATLAB, you can use the "table" function. Here's an example of how to create a table with column names "Name", "Age", and "Gender":

main.m
% Create example data
names = {'Alice'; 'Bob'; 'Charlie'};
ages = [25; 30; 35];
genders = {'F'; 'M'; 'M'};

% Create table
T = table(names, ages, genders);
156 chars
8 lines

This will create a table T with three columns, "Name", "Age", and "Gender", and three rows with the corresponding data.

You can then access the data in the table using various indexing methods. For example, to get the ages of all individuals in the table, you can use:

main.m
ages = T.Age;
14 chars
2 lines

Note that column names are accessed using dot notation, and are case-sensitive.

You can also add additional columns to the table using the same syntax as above.

related categories

gistlibby LogSnag