The table Data Type
A MATLAB table stores column-oriented data where each column (called a variable) can hold a different type — numeric, string, categorical, or even nested cell arrays — as long as all columns have the same number of rows. You construct one directly with table(col1, col2, 'VariableNames', {'Name1', 'Name2'}), and access columns using dot notation, T.ColumnName, or curly-brace indexing, T.ColumnName(1:5), to extract raw values rather than a sub-table. Row names can be assigned via T.Properties.RowNames = {'r1','r2',...}, which allows indexing rows by label, T('r1', :), similar to indexing a dictionary by key rather than only by numeric position.
Cricket analogy: A table with columns 'Batsman', 'Runs', and 'StrikeRate' holding text, numeric, and numeric data side by side mirrors exactly how a scorecard organizes heterogeneous stats per player in one structured sheet.
Names = {'Alice'; 'Bob'; 'Carol'};
Age = [34; 28; 45];
Score = [88.5; 92.1; 79.3];
T = table(Names, Age, Score, 'VariableNames', {'Name','Age','Score'});
disp(T(T.Score > 85, :)); % filter rows by condition
T.Passed = T.Score >= 80; % add a new derived columnFiltering, Sorting, and Modifying Tables
Tables support logical row indexing directly, so T(T.Age > 30, :) returns only the rows where the Age column exceeds 30, combining filtering syntax familiar from numeric arrays with named-column access. sortrows(T, 'Score', 'descend') reorders all rows by the Score column while keeping every other column's values correctly aligned to their original row, which is far less error-prone than manually sorting parallel numeric arrays. New columns can be added simply by assignment, T.NewColumn = someVector, provided the vector's length matches the table's height, and removevars(T, 'ColumnName') or T.ColumnName = [] deletes a column cleanly.
Cricket analogy: sortrows(T,'Score','descend') reordering a batting table by highest score while keeping player names correctly attached mirrors a leaderboard auto-sorting by runs without mismatching any player's name to the wrong score.
Import Tool and Automated Import Functions
The interactive Import Tool, launched by double-clicking a data file in the Current Folder browser or calling uiimport(filename), lets you preview a spreadsheet or text file, adjust delimiter and range detection, choose the output type (table, column vectors, or numeric matrix), and then generate reusable MATLAB code via 'Generate Script' that replicates the import programmatically. detectImportOptions(filename) inspects a file and returns an options object describing its inferred delimiter, variable names, and types, which you can adjust (for example, opts.VariableTypes{3} = 'categorical') before passing it to readtable(filename, opts) for precise, repeatable control over how ambiguous columns get imported.
Cricket analogy: Using the Import Tool to preview a raw match-log CSV before committing to an import is like a scorer double-checking a paper scoresheet's column layout before transcribing it into the official digital record.
detectImportOptions + readtable(filename, opts) is the recommended pattern for repeatable, script-based imports of files with ambiguous or mixed column types, since it avoids re-guessing formats on every run and documents the exact import configuration in code.
readtable's automatic type detection can misclassify columns — for example, a column of numeric-looking ID codes with leading zeros may be imported as numbers, silently dropping the leading zeros; always verify T.Properties.VariableTypes after import for such columns.
- A table stores column-oriented, heterogeneously typed data with named variables (columns) of equal length.
- Columns are accessed via dot notation, T.ColumnName, and rows can be filtered with logical indexing.
- sortrows(T, 'ColumnName') sorts all rows while preserving correct row alignment across columns.
- New columns are added by simple assignment; removevars or T.Col = [] deletes a column.
- The interactive Import Tool (uiimport) lets you preview and configure an import, then generate reusable code.
- detectImportOptions + readtable(file, opts) gives precise, scriptable control over column types on import.
- Always verify inferred column types after import, especially for ID-like numeric-looking text columns.
Practice what you learned
1. What is the defining characteristic of a MATLAB table's columns?
2. How do you filter a table T to only rows where Age exceeds 30?
3. What does sortrows(T, 'Score', 'descend') guarantee?
4. What does detectImportOptions(filename) return?
5. Why should you verify T.Properties.VariableTypes after importing a file with ID-like columns?
Was this page helpful?
You May Also Like
Reading and Writing Data Files
Learn MATLAB's core file I/O functions for reading and writing text, CSV, and binary data, including readmatrix, writematrix, and low-level fopen/fprintf.
Plotting Basics in MATLAB
Learn how to create, label, and style 2-D line plots in MATLAB using the plot function, and how to control colors, markers, and axes.
Curve Fitting and Interpolation
Learn to fit polynomial and custom models to data with polyfit and fit, and estimate values between known data points using interp1 and related interpolation functions.
Related Reading
Related Study Notes in Programming
Browse all study notesApache Spark Study Notes
Programming · 30 topics
ProgrammingApache Flink Study Notes
Programming · 30 topics
ProgrammingHadoop Study Notes
Programming · 30 topics
ProgrammingSnowflake Study Notes
Programming · 30 topics
ProgrammingApache Airflow Study Notes
Programming · 30 topics
Programmingdbt (Data Build Tool) Study Notes
Programming · 30 topics