100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Programming

Tables and Data Import

Work with MATLAB's table data type for organizing heterogeneous data with named columns, and use the Import Tool and related functions to bring in external datasets.

Plotting & DataIntermediate9 min readJul 10, 2026
Analogies

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.

matlab
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 column

Filtering, 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

Was this page helpful?

Topics covered

#Programming#MATLABStudyNotes#TablesAndDataImport#Tables#Data#Import#Table#StudyNotes#SkillVeris#ExamPrep