matlab/matlab-agentic-toolkit / skills-catalog/signal-processing/matlab-prepare-signal-data
matlab-prepare-signal-data
VerifiedUse this skill when conditioning, loading, preparing, or labeling signal data for analysis or ML training. Covers: cleaning a single signal (fill gaps, remove drift, deoutlier, denoise, resample/align a time base) BEFORE analysis; building a `signalDatastore` pipeline; creating a `labeledSignalSet` for Signal Labeler; deriving labels (filename, folder, in-file, ROI, time-frequency ROI); stratified train/val/test splits; framing long signals; parallel processing; and shaping datastore output for `trainnet`. Triggers include "clean up this signal", "remove drift / detrend", "fill gaps", "remove spikes / outliers", "denoise", "resample to a uniform rate", "align channels", "labels from filenames", "stratified split", "prepare for Signal Labeler", and function names like `fillgaps`, `fillmissing`, `detrend`, `filloutliers`, `smoothdata`, `resample`, `synchronize`, `signalDatastore`, `labeledSignalSet`, `filenames2labels`, `folders2labels`, `splitlabels`, `framesig`, `framelbl`, `createDatastores`.
references/fn-subset.md
View on GitHub# Function: `subset` (Sense 1 — split)
> Used in: wf-load-and-split.md
> Toolbox: MATLAB datastore API (works on `signalDatastore`)
Slice a datastore by **index vector** to produce a smaller datastore.
**This is the split sense of partition** — used to carve a single datastore
into train / val / test on one worker. Distinct from `partition(ds, N, k)`
which shards a datastore across parallel workers (see fn-partition.md).
## Two senses of "partition" — disambiguate
| Sense | Function | Use when |
|---|---|---|
| **1. Split** (single-worker train/val/test) | `subset(ds, idx)` | You have indices from `splitlabels` and need three datastores. **This file.** |
| **2. Parallel** (multi-worker sharding) | `partition(ds, N, k)` | You're inside a `parfor` and want each worker to process a disjoint share of files. See fn-partition.md. |
## Signature
```matlab
sliceDs = subset(ds, idx)
```
- `ds` — a datastore (e.g. `signalDatastore`).
- `idx` — either a numeric vector of file indices (1-based, into
`ds.Files`) or a logical vector of length `numel(ds.Files)`.
Returns a new datastore restricted to the selected files, in the order
given.
### Input forms for `idx`
| Form | Example | Result |
|---|---|---|
| Numeric index vector | `subset(sds, [3 1 2 5 4])` | 5 files in that exact order (order preserved). |
| Logical mask | `subset(sds, [T F T T F])` | The files at the `true` positions (here: 3 files). |
| Duplicates allowed | `subset(sds, [1 1 2])` | 3 files (file 1 listed twice, then file 2). |
## Canonical pattern — with `splitlabels`
```matlab
splitIndices = splitlabels(labels, [0.7 0.15 0.15]);
sdsTrain = subset(sds, splitIndices{1});
sdsVal = subset(sds, splitIndices{2});
sdsTest = subset(sds, splitIndices{3});
```
`splitlabels` returns an `(N+1)`-element cell array of index vectors;
`subset` takes one of those vectors and returns the corresponding shard.
The 4th cell `splitIndices{4}` is empty when ratios sum to 1 (as above)
and holds the leftover indices when `sum(ratios) < 1`.
## Anti-pattern
Don't try to feed `splitlabels` output into `cvpartition` for k-fold.
`splitlabels(labels, [0.7 0.15 0.15])` returns a **cell array of index
vectors** — there is no `cvpartition` constructor that consumes that
shape.
The canonical chain for datastore-backed splits is `splitlabels` →
`subset`; stay in that index-vector world.
```matlab
% Bad — splitlabels output is a cell, not a cvpartition input:
splitIndices = splitlabels(labels, [0.7 0.15 0.15]);
cv = cvpartition(splitIndices, "KFold", 5); % no method takes a cell
% Good — use splitlabels' cell directly:
sdsTrain = subset(sds, splitIndices{1});
sdsVal = subset(sds, splitIndices{2});
sdsTest = subset(sds, splitIndices{3});
```
(For the inverse direction, `cvpartition`'s `training`/`test` methods
return numeric index vectors that *can* be passed to `subset` — but
prefer `splitlabels` because it stratifies on the label vector natively.)
## Gotchas
- **`idx` is into `ds.Files`, not into your label vector.** When `labels`
was derived from `sds` (via `filenames2labels` or `folders2labels`),
`labels(k)` corresponds to `sds.Files{k}` — so the index spaces line up
by construction. If you reorder either, they don't. After
`transform(sds, ...)` or `combine(sds, otherDs)` the resulting
TransformedDatastore / CombinedDatastore preserves the underlying file
order, so `idx` still indexes into the original `sds.Files` order — but
this is only safe as long as you haven't shuffled or sliced the inner
datastore separately.
- **`subset` is order-preserving.** `subset(ds, [3 1 2])` returns a
datastore reading file 3, then 1, then 2. Useful for shuffling.
## See also
- `fn-partition.md` — Sense 2 of partition (multi-worker parallel sharding).
- `fn-splitlabels.md` — produces the index vectors that `subset` consumes.
- For the chain `splitlabels` → `subset`, see wf-load-and-split.md (step 4).
----
Copyright 2026 The MathWorks, Inc.
----
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |