Next: , Up: Table Representation   [Contents]


3.1 Table Construction

There are two main ways to construct a table array: build one up by combining multiple variables together, or convert an existing tabular-organized array into a table.

To build an array from multiple variables, use the table(…) constructor, passing in all of your variables as separate inputs. It takes any number of inputs. Each input becomes a table variable in the new table object. If you pass your constructor inputs directly from variables, it automatically picks up their names and uses them as the table variable names. Otherwise, if you’re using more complex expressions, you’ll need to supply the 'VariableNames' option.

To convert a tabular-organized array of another type into a table, use the conversion functions like array2table, struct2table and cell2table. array2table and cell2table take each column of the input array and turn it into a separate table variable in the resulting table. struct2table takes the fields of a struct and puts them into table variables.