$npx -y skills add matlab/matlab-agentic-toolkit --skill matlab-analyze-dataAnalyze 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 answer
| 1 | # MATLAB Data Analysis |
| 2 | |
| 3 | Generate idiomatic MATLAB code for tabular data analysis tasks using tables and timetables. |
| 4 | |
| 5 | ## When to Use |
| 6 | |
| 7 | - Any task involving tabular data: exploring, cleaning, transforming, or aggregating tables |
| 8 | - Time-series analysis: resampling, synchronizing, trend detection, smoothing |
| 9 | - Answering questions about data in tables (top-N, filtering, group comparisons) |
| 10 | - Data cleaning: missing values, outliers, type conversion, normalization |
| 11 | |
| 12 | ## When NOT to Use |
| 13 | |
| 14 | - The task has no tabular data context (no tables, timetables, or structured datasets) |
| 15 | - The primary goal is visualization or plotting, not data analysis |
| 16 | - The task is purely symbolic math, simulation, or app building |
| 17 | |
| 18 | This skill covers core MATLAB functions for tabular and time-series workflows. These functions work natively with `table` and `timetable`, handle missing data correctly, and are performance-optimized. Prefer the modern functions recommended here (e.g., `groupsummary`, `datetime`, `fillmissing`) over legacy alternatives (e.g., `accumarray`, `nanmean`, `datenum`). Override only if the user explicitly requests otherwise. |
| 19 | |
| 20 | **Before writing code, read the reference file linked at the end of the relevant section below.** 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. |
| 21 | |
| 22 | ### Key Functions — Available From |
| 23 | |
| 24 | Most functions in this skill are available in R2023a or earlier. The following require a newer release: |
| 25 | |
| 26 | | Function | Available From | Purpose | |
| 27 | |----------|---------------|---------| |
| 28 | | `paddata`, `trimdata`, `resize` | R2023b | Pad, trim, or resize arrays to target length | |
| 29 | | `clip` | R2024a | Clamp values to a range | |
| 30 | | `summary` (enhanced) | R2024b | Supports arrays (numeric, datetime, duration, logical); adds `Statistics`, `DataVariables`, `Detail` name-value args | |
| 31 | | `isapprox` | R2024b | Tolerance-aware floating-point comparison (use instead of `==` for computed values) | |
| 32 | | `isbetween` (numeric) | R2024b | Check elements within a numeric range | |
| 33 | | `numunique` | R2025a | Count distinct values in a variable | |
| 34 | | `allbetween` | R2025a | Validate all values are within a range | |
| 35 | | `allunique` | R2025a | Validate all values are unique | |
| 36 | |
| 37 | ## Getting Oriented with Data |
| 38 | |
| 39 | When data is already in a workspace variable, start by understanding its structure and contents. Use JSON output for reliable parsing — table display is designed for human-readable grids, but as text it is easy to misinterpret which values belong to which variables: |
| 40 | |
| 41 | ```matlab |
| 42 | jsonencode(summary(T)) % per-variable stats as nested struct |
| 43 | jsonencode(head(T)) % first 8 rows as structured JSON |
| 44 | ``` |
| 45 | |
| 46 | **When getting oriented with unknown data, `summary(T)` already contains per-variable type, size, NumMissing, and — for numeric/datetime/duration — Min, Max, Mean, Median, Std. For categoricals it includes category names and counts.** This is usually sufficient for an initial overview. |
| 47 | |
| 48 | If producing a standalone script, leave the semicolon off to invoke the `display` method — it shows dimensions, variable names, and a truncated preview. Avoid `disp` (omits headers and prints every row, flooding output on large tables) and `fprintf` in a loop (verbose, old-style): |
| 49 | |
| 50 | ```matlab |
| 51 | summary(T) % types, ranges, missing counts per variable |
| 52 | size(T) % [nRows, nVars] |
| 53 | sum(ismissing(T)) % missing count per variable |
| 54 | T % dimensions + header + truncated preview |
| 55 | ``` |
| 56 | |
| 57 | **For Pearson correlation, use `corrcoef` (base MATLAB)** with `Rows="complete"` to handle NaN: `corrcoef(T{:,vartype("numeric")}, Rows="complete")`. For Kendall or Spearman rank correlation, use `corr` (requires Statistics Toolbox): `corr(X, Type="Spearman")`. |
| 58 | |
| 59 | > Systematic exploration checklist (distributions, cardinality, duplicates, outlier screening, `groupcounts`, `corrcoef`, time-based checks): [exploration.md](references/exploration.md) |
| 60 | |
| 61 | ## Data Types |
| 62 | |
| 63 | Use modern MATLAB types. These are faster, more readable, and work better with table functions. |
| 64 | |
| 65 | | Instead of | Use | Why | |
| 66 | |---|---|---| |
| 67 | | `datenum`, `datestr` | `datetime` | Proper arithmetic, timezone support | |
| 68 | | `char`, `cellstr`, `strcmp` | `string`, `==`/`matches` | `==` for scalar, `matches` for vector comparison | |
| 69 | | Numeric codes or strings with few unique values | `categorical` | Self-documenting, works wit |