MATLAB Data Analysis
Generate idiomatic MATLAB code for tabular data analysis tasks using tables and timetables.
When to Use
- Any task involving tabular data: exploring, cleaning, transforming, or aggregating tables
- Time-series analysis: resampling, synchronizing, trend detection, smoothing
- Answering questions about data in tables (top-N, filtering, group comparisons)
- Data cleaning: missing values, outliers, type conversion, normalization
When NOT to Use
- The task has no data context (no tables, timetables, arrays, or date/time values to work with)
- The primary goal is visualization or plotting, not data analysis (use
matlab-build-chart instead)
- The task is purely symbolic math, simulation, or app building
- Reading or writing files — CSV, Excel, Parquet, MAT-file (use
matlab-import-export-data instead)
- Data doesn't fit in memory or requires out-of-core processing (use
matlab-choose-big-data-solution instead)
- Storing or retrieving passwords, tokens, or API keys (use
matlab-secure-credentials instead)
- Data lives in a relational database (use
matlab-use-database or matlab-use-duckdb instead)
- Building an ML training pipeline from labeled signal files (use
matlab-prepare-signal-data instead)
- Code migration or replacing deprecated APIs (use
matlab-modernize-code instead)
How to Use This Skill
This skill covers core MATLAB functions for tabular, time-series, and array-based data workflows — including numeric arrays, sensor matrices, and gridded data. These functions work natively with table, timetable, and numeric arrays, handle missing data correctly, and are performance-optimized. Prefer the modern functions recommended here (e.g., groupsummary, datetime, fillmissing, smoothdata2) over legacy alternatives (e.g., accumarray, nanmean, datenum). Override only if the user explicitly requests otherwise.
Each section below links to a reference file. ALWAYS read the reference file for the relevant topic before writing code. Reference files contain correct syntax, common pitfalls, and "Avoid" patterns that prevent silent bugs. Skipping the reference risks using a deprecated approach or hitting a known pitfall.
Key Functions — Available From
Most functions in this skill are available in R2023a or earlier. The following require a newer release:
| Function |
Available From |
Purpose |
paddata, trimdata, resize |
R2023b |
Pad, trim, or resize arrays to target length |
smoothdata2 |
R2023b |
Smooth 2-D gridded data over rectangular windows |
clip |
R2024a |
Clamp values to a range |
islocalmax2, islocalmin2 |
R2024a |
Detect local extrema in 2-D gridded data |
summary (enhanced) |
R2024b |
Supports arrays (numeric, datetime, duration, logical); adds Statistics, DataVariables, Detail name-value args |
isapprox |
R2024b |
Tolerance-aware floating-point comparison (use instead of == for computed values) |
isbetween (numeric) |
R2024b |
Check elements within a numeric range |
numunique |
R2025a |
Count distinct values in a variable |
allbetween |
R2025a |
Validate all values are within a range |
allunique |
R2025a |
Validate all values are unique |
Getting Oriented with Data
When data is already in a workspace variable, start by understanding its structure and contents before writing analysis code.
Topics:
- Summarizing structure, shape, and variable types
- Assessing how much data is missing and where
- Understanding distributions (numeric quartiles, categorical value counts)
- Finding correlations and relationships between variables
- Checking for duplicates, unique keys, and cardinality
- Exploring time range, regularity, and temporal patterns
Functions: summary, head, size, jsonencode, anymissing, allfinite, ismissing, groupcounts, numunique, corrcoef, pivot, unique, isregular, isuniform, retime
Read: exploration.md
Data Types
Use modern MATLAB types instead of legacy alternatives. Modern types are faster, more readable, and work better with table functions.
Topics:
- Dates and times (parsing, arithmetic, timezones, extracting year/month/day/hour)
- Elapsed time and calendar offsets
- Text data (comparing, searching, splitting, editing strings)
- Categorical data (ordinal rankings, merging/renaming/reordering levels)
Functions: datetime, dateshift, year, month, day, weekday, quarter, hour, ymd, hms, hours, days, minutes, seconds, calmonths, caldays, string, matches, contains, startsWith, extractAfter, extractBefore, replace, erase, strip, split, count, categorical, mergecats, renamecats, removecats, reordercats, countcats
Read: data-types.md
Tables and Timetables
Tables are the primary container for tabular data. Use timetable when the data has timestamps, a time vector, or a known sample rate — it unlocks time-aware operations (automatic spacing-aware smoothing, filling, and resampling).
Topics:
- Creating and structuring tables (variables vs rows, metadata, properties)
- Selecting variables by type; dot indexing vs braces vs parentheses
- Converting variable types after import
- Working with non-uniformly spaced data (
SamplePoints)
- Resampling, aligning, and synchronizing time series
- Filtering by date range or time tolerance
- Converting legacy
timeseries objects
Functions: table, timetable, table2timetable, vartype, convertvars, retime, synchronize, lag, timerange, withtol, timeseries2timetable, table2array, array2table
Read: tables-and-timetables.md
Eventtables
Use eventtable when tagging or annotating timetable rows with events, episodes, or phases (sensor anomalies, storms, maintenance windows, alarms). Do NOT add boolean columns, string labels, or categorical state variables to the timetable itself.
Topics:
- Creating an eventtable from timestamps and labels (instantaneous or interval)
- Attaching events to a timetable
- Filtering timetable rows by event properties
- Extracting events from patterns in data (peaks, threshold crossings)
- Pushing event data into timetable rows for export or grouping
- Automatic event overlays in plots
Functions: eventtable, eventfilter, extractevents, syncevents, withtol, stackedplot
Read: eventtables.md
Data Cleaning
Handle missing values and outliers using MATLAB's built-in detection and fill functions. Never compare with == for missing values. Use standardizeMissing to convert sentinel values before filling or removing.
Topics:
- Detecting missing values (NaN, NaT, missing strings, undefined categoricals)
- Converting placeholder values ("N/A", -999, "") to standard missing
- Filling gaps (interpolation, forward-fill, moving window, per-type strategies)
- Limiting fill across long gaps
- Skipping missing values in aggregation (mean, std, min, max) — correct calling syntax
- Detecting, removing, or replacing outliers
- Checking whether values fall within an expected range; clamping
Functions: ismissing, anymissing, standardizeMissing, fillmissing, rmmissing, isoutlier, rmoutliers, filloutliers, isbetween, allbetween, clip, isapprox
Read: data-cleaning.md
Data Transformation
Filter, sort, reshape, normalize, bin, join, and manage table variables. Use vectorized operations and built-in functions — not loops over rows or manual if-else chains.
Topics:
- Filtering rows by condition or value range
- Sorting and retrieving top/bottom N rows
- Applying functions across rows or across variables
- Renaming, reordering, adding, removing, splitting, merging variables
- Converting types and applying in-place transforms
- Binning continuous values into categories
- Normalizing, scaling, z-scoring
- Reshaping between wide and tall formats (pivot, stack, unstack)
- Joining/merging tables on key variables
Functions: sortrows, topkrows, rowfun, varfun, convertvars, renamevars, movevars, addvars, removevars, splitvars, mergevars, discretize, normalize, clip, rescale, pivot, stack, unstack, rows2vars, innerjoin, outerjoin, join
Read: data-transformation.md
Grouping and Aggregation
groupsummary is the go-to for grouped statistics — not findgroups+accumarray or manual loops. Use groupfilter for per-group row filtering, grouptransform for per-group normalization, and pivot for cross-tabulation.
Topics:
- Computing statistics by group (mean, sum, std, min, max, custom)
- Binning on the fly (numeric edges, hourly/monthly/seasonal time bins)
- Handling missing or empty groups
- Filtering rows based on group-level conditions (e.g., minimum group size)
- Removing per-group outliers
- Normalizing within each group (z-score, rescale)
- Cross-tabulating counts or aggregated values
Functions: groupsummary, groupcounts, groupfilter, grouptransform, pivot, findgroups
Read: grouping-and-aggregation.md
Smoothing, Trends, and Patterns
smoothdata is the unified entry point for smoothing (not smooth, which requires Curve Fitting Toolbox). Use detrend or trenddecomp for trend removal/decomposition, and islocalmax/islocalmin/ischange for pattern detection.
Topics:
- Smoothing noisy data (moving average, Gaussian, Savitzky-Golay, median)
- Choosing window size (element count vs duration for time-stamped data)
- Removing linear or polynomial trends
- Separating trend from seasonality (seasonal decomposition)
- Finding peaks, valleys, and local extrema
- Detecting abrupt changes in mean, variance, or slope
- Summarizing distributions (bin counts, histograms)
Functions: smoothdata, movmean, movmedian, detrend, trenddecomp, islocalmax, islocalmin, ischange, histcounts, histogram
Read: smoothing-and-trends.md
Array and Grid Data
Use arrays when data is homogeneous numeric AND either naturally 2D/grid, performance-critical, or delivered by upstream tooling. For 2D grids, use dedicated 2D functions — do not loop 1D functions over rows/columns.
Topics:
- When to stay in arrays vs converting to table
- Operating along a specific dimension (row-wise vs column-wise)
- Common pitfalls with dimension arguments in std, var, movstd, movvar
- Handling NaN in array computations (not automatic)
- Moving window and cumulative statistics
- Padding, trimming, or resizing arrays to a target length
- 2D spatial smoothing, gap filling, and peak detection on grids
- Grouped operations using a grouping vector
Functions: smoothdata2, fillmissing2, islocalmax2, islocalmin2, paddata, trimdata, resize, mink, maxk, bounds, rms, prctile, quantile, iqr, cumsum, cummax, cummin, cumprod, movmean, movmedian, movsum, movstd, movvar, isuniform, isregular
Read: array-and-grid-data.md
Answering Questions About Data
When the task is answering a specific question about data (top-N, filtering, lookups, comparisons), read the strategies reference to avoid common mistakes with sorting direction, missing data, and value interpretation.
Topics:
- Finding the highest/lowest/top/bottom N entries
- Looking up values in one column based on ranking in another
- Accounting for missing or placeholder values in answers
- Returning raw data values without substitution or mapping
- Counting rows that match a condition (exact vs partial text matching)
Functions: topkrows, sortrows, groupsummary, standardizeMissing, matches, contains, height, nnz
Read: answering-data-questions.md
Copyright 2026 The MathWorks, Inc.
1---2name: matlab-analyze-data3description: Analyze data using MATLAB. Use when the task involves tables, timetables, time-series data, numeric arrays, sensor matrices, or gridded data — including but not limited to exploring, filtering, sorting, cleaning, transforming, aggregating, smoothing, padding, trimming, and answering questions about data. MATLAB provides extensive, easy-to-use built-in functions for these workflows with no additional products required.4license: https://www.mathworks.com/content/dam/mathworks/license/pmrl/lic5---67# MATLAB Data Analysis89Generate idiomatic MATLAB code for tabular data analysis tasks using tables and timetables.1011## When to Use1213- Any task involving tabular data: exploring, cleaning, transforming, or aggregating tables14- Time-series analysis: resampling, synchronizing, trend detection, smoothing15- Answering questions about data in tables (top-N, filtering, group comparisons)16- Data cleaning: missing values, outliers, type conversion, normalization1718## When NOT to Use1920- The task has no data context (no tables, timetables, arrays, or date/time values to work with)21- The primary goal is visualization or plotting, not data analysis (use `matlab-build-chart` instead)22- The task is purely symbolic math, simulation, or app building23- Reading or writing files — CSV, Excel, Parquet, MAT-file (use `matlab-import-export-data` instead)24- Data doesn't fit in memory or requires out-of-core processing (use `matlab-choose-big-data-solution` instead)25- Storing or retrieving passwords, tokens, or API keys (use `matlab-secure-credentials` instead)26- Data lives in a relational database (use `matlab-use-database` or `matlab-use-duckdb` instead)27- Building an ML training pipeline from labeled signal files (use `matlab-prepare-signal-data` instead)28- Code migration or replacing deprecated APIs (use `matlab-modernize-code` instead)2930## How to Use This Skill3132This skill covers core MATLAB functions for tabular, time-series, and array-based data workflows — including numeric arrays, sensor matrices, and gridded data. These functions work natively with `table`, `timetable`, and numeric arrays, handle missing data correctly, and are performance-optimized. Prefer the modern functions recommended here (e.g., `groupsummary`, `datetime`, `fillmissing`, `smoothdata2`) over legacy alternatives (e.g., `accumarray`, `nanmean`, `datenum`). Override only if the user explicitly requests otherwise.3334**Each section below links to a reference file. ALWAYS read the reference file for the relevant topic before writing code.** Reference files contain correct syntax, common pitfalls, and "Avoid" patterns that prevent silent bugs. Skipping the reference risks using a deprecated approach or hitting a known pitfall.3536### Key Functions — Available From3738Most functions in this skill are available in R2023a or earlier. The following require a newer release:3940| Function | Available From | Purpose |41|----------|---------------|---------|42| `paddata`, `trimdata`, `resize` | R2023b | Pad, trim, or resize arrays to target length |43| `smoothdata2` | R2023b | Smooth 2-D gridded data over rectangular windows |44| `clip` | R2024a | Clamp values to a range |45| `islocalmax2`, `islocalmin2` | R2024a | Detect local extrema in 2-D gridded data |46| `summary` (enhanced) | R2024b | Supports arrays (numeric, datetime, duration, logical); adds `Statistics`, `DataVariables`, `Detail` name-value args |47| `isapprox` | R2024b | Tolerance-aware floating-point comparison (use instead of `==` for computed values) |48| `isbetween` (numeric) | R2024b | Check elements within a numeric range |49| `numunique` | R2025a | Count distinct values in a variable |50| `allbetween` | R2025a | Validate all values are within a range |51| `allunique` | R2025a | Validate all values are unique |5253---5455## Getting Oriented with Data5657When data is already in a workspace variable, start by understanding its structure and contents before writing analysis code.5859**Topics:**60- Summarizing structure, shape, and variable types61- Assessing how much data is missing and where62- Understanding distributions (numeric quartiles, categorical value counts)63- Finding correlations and relationships between variables64- Checking for duplicates, unique keys, and cardinality65- Exploring time range, regularity, and temporal patterns6667**Functions:** `summary`, `head`, `size`, `jsonencode`, `anymissing`, `allfinite`, `ismissing`, `groupcounts`, `numunique`, `corrcoef`, `pivot`, `unique`, `isregular`, `isuniform`, `retime`6869**Read:** [exploration.md](references/exploration.md)7071---7273## Data Types7475Use modern MATLAB types instead of legacy alternatives. Modern types are faster, more readable, and work better with table functions.7677**Topics:**78- Dates and times (parsing, arithmetic, timezones, extracting year/month/day/hour)79- Elapsed time and calendar offsets80- Text data (comparing, searching, splitting, editing strings)81- Categorical data (ordinal rankings, merging/renaming/reordering levels)8283**Functions:** `datetime`, `dateshift`, `year`, `month`, `day`, `weekday`, `quarter`, `hour`, `ymd`, `hms`, `hours`, `days`, `minutes`, `seconds`, `calmonths`, `caldays`, `string`, `matches`, `contains`, `startsWith`, `extractAfter`, `extractBefore`, `replace`, `erase`, `strip`, `split`, `count`, `categorical`, `mergecats`, `renamecats`, `removecats`, `reordercats`, `countcats`8485**Read:** [data-types.md](references/data-types.md)8687---8889## Tables and Timetables9091Tables are the primary container for tabular data. Use `timetable` when the data has timestamps, a time vector, or a known sample rate — it unlocks time-aware operations (automatic spacing-aware smoothing, filling, and resampling).9293**Topics:**94- Creating and structuring tables (variables vs rows, metadata, properties)95- Selecting variables by type; dot indexing vs braces vs parentheses96- Converting variable types after import97- Working with non-uniformly spaced data (`SamplePoints`)98- Resampling, aligning, and synchronizing time series99- Filtering by date range or time tolerance100- Converting legacy `timeseries` objects101102**Functions:** `table`, `timetable`, `table2timetable`, `vartype`, `convertvars`, `retime`, `synchronize`, `lag`, `timerange`, `withtol`, `timeseries2timetable`, `table2array`, `array2table`103104**Read:** [tables-and-timetables.md](references/tables-and-timetables.md)105106---107108## Eventtables109110Use `eventtable` when tagging or annotating timetable rows with events, episodes, or phases (sensor anomalies, storms, maintenance windows, alarms). Do NOT add boolean columns, string labels, or categorical state variables to the timetable itself.111112**Topics:**113- Creating an eventtable from timestamps and labels (instantaneous or interval)114- Attaching events to a timetable115- Filtering timetable rows by event properties116- Extracting events from patterns in data (peaks, threshold crossings)117- Pushing event data into timetable rows for export or grouping118- Automatic event overlays in plots119120**Functions:** `eventtable`, `eventfilter`, `extractevents`, `syncevents`, `withtol`, `stackedplot`121122**Read:** [eventtables.md](references/eventtables.md)123124---125126## Data Cleaning127128Handle missing values and outliers using MATLAB's built-in detection and fill functions. Never compare with `==` for missing values. Use `standardizeMissing` to convert sentinel values before filling or removing.129130**Topics:**131- Detecting missing values (NaN, NaT, missing strings, undefined categoricals)132- Converting placeholder values ("N/A", -999, "") to standard missing133- Filling gaps (interpolation, forward-fill, moving window, per-type strategies)134- Limiting fill across long gaps135- Skipping missing values in aggregation (mean, std, min, max) — correct calling syntax136- Detecting, removing, or replacing outliers137- Checking whether values fall within an expected range; clamping138139**Functions:** `ismissing`, `anymissing`, `standardizeMissing`, `fillmissing`, `rmmissing`, `isoutlier`, `rmoutliers`, `filloutliers`, `isbetween`, `allbetween`, `clip`, `isapprox`140141**Read:** [data-cleaning.md](references/data-cleaning.md)142143---144145## Data Transformation146147Filter, sort, reshape, normalize, bin, join, and manage table variables. Use vectorized operations and built-in functions — not loops over rows or manual if-else chains.148149**Topics:**150- Filtering rows by condition or value range151- Sorting and retrieving top/bottom N rows152- Applying functions across rows or across variables153- Renaming, reordering, adding, removing, splitting, merging variables154- Converting types and applying in-place transforms155- Binning continuous values into categories156- Normalizing, scaling, z-scoring157- Reshaping between wide and tall formats (pivot, stack, unstack)158- Joining/merging tables on key variables159160**Functions:** `sortrows`, `topkrows`, `rowfun`, `varfun`, `convertvars`, `renamevars`, `movevars`, `addvars`, `removevars`, `splitvars`, `mergevars`, `discretize`, `normalize`, `clip`, `rescale`, `pivot`, `stack`, `unstack`, `rows2vars`, `innerjoin`, `outerjoin`, `join`161162**Read:** [data-transformation.md](references/data-transformation.md)163164---165166## Grouping and Aggregation167168`groupsummary` is the go-to for grouped statistics — not `findgroups`+`accumarray` or manual loops. Use `groupfilter` for per-group row filtering, `grouptransform` for per-group normalization, and `pivot` for cross-tabulation.169170**Topics:**171- Computing statistics by group (mean, sum, std, min, max, custom)172- Binning on the fly (numeric edges, hourly/monthly/seasonal time bins)173- Handling missing or empty groups174- Filtering rows based on group-level conditions (e.g., minimum group size)175- Removing per-group outliers176- Normalizing within each group (z-score, rescale)177- Cross-tabulating counts or aggregated values178179**Functions:** `groupsummary`, `groupcounts`, `groupfilter`, `grouptransform`, `pivot`, `findgroups`180181**Read:** [grouping-and-aggregation.md](references/grouping-and-aggregation.md)182183---184185## Smoothing, Trends, and Patterns186187`smoothdata` is the unified entry point for smoothing (not `smooth`, which requires Curve Fitting Toolbox). Use `detrend` or `trenddecomp` for trend removal/decomposition, and `islocalmax`/`islocalmin`/`ischange` for pattern detection.188189**Topics:**190- Smoothing noisy data (moving average, Gaussian, Savitzky-Golay, median)191- Choosing window size (element count vs duration for time-stamped data)192- Removing linear or polynomial trends193- Separating trend from seasonality (seasonal decomposition)194- Finding peaks, valleys, and local extrema195- Detecting abrupt changes in mean, variance, or slope196- Summarizing distributions (bin counts, histograms)197198**Functions:** `smoothdata`, `movmean`, `movmedian`, `detrend`, `trenddecomp`, `islocalmax`, `islocalmin`, `ischange`, `histcounts`, `histogram`199200**Read:** [smoothing-and-trends.md](references/smoothing-and-trends.md)201202---203204## Array and Grid Data205206Use arrays when data is homogeneous numeric AND either naturally 2D/grid, performance-critical, or delivered by upstream tooling. For 2D grids, use dedicated 2D functions — do not loop 1D functions over rows/columns.207208**Topics:**209- When to stay in arrays vs converting to table210- Operating along a specific dimension (row-wise vs column-wise)211- Common pitfalls with dimension arguments in std, var, movstd, movvar212- Handling NaN in array computations (not automatic)213- Moving window and cumulative statistics214- Padding, trimming, or resizing arrays to a target length215- 2D spatial smoothing, gap filling, and peak detection on grids216- Grouped operations using a grouping vector217218**Functions:** `smoothdata2`, `fillmissing2`, `islocalmax2`, `islocalmin2`, `paddata`, `trimdata`, `resize`, `mink`, `maxk`, `bounds`, `rms`, `prctile`, `quantile`, `iqr`, `cumsum`, `cummax`, `cummin`, `cumprod`, `movmean`, `movmedian`, `movsum`, `movstd`, `movvar`, `isuniform`, `isregular`219220**Read:** [array-and-grid-data.md](references/array-and-grid-data.md)221222---223224## Answering Questions About Data225226When the task is answering a specific question about data (top-N, filtering, lookups, comparisons), read the strategies reference to avoid common mistakes with sorting direction, missing data, and value interpretation.227228**Topics:**229- Finding the highest/lowest/top/bottom N entries230- Looking up values in one column based on ranking in another231- Accounting for missing or placeholder values in answers232- Returning raw data values without substitution or mapping233- Counting rows that match a condition (exact vs partial text matching)234235**Functions:** `topkrows`, `sortrows`, `groupsummary`, `standardizeMissing`, `matches`, `contains`, `height`, `nnz`236237**Read:** [answering-data-questions.md](references/answering-data-questions.md)238239---240241Copyright 2026 The MathWorks, Inc.