trimdata
Trims an array down to a target size.
Category: Language Fundamentals > Matrices and Arrays
Syntax
B = trimdata(A, n)
Keeps the first n elements along the first non-singleton dimension.
B = trimdata(A, sz)
Trims to the size vector sz, one entry per dimension.
B = trimdata(___, 'Side', s)
Chooses which end is removed: 'trailing' (default), 'leading' or 'both'.
B = trimdata(___, 'Dimension', d)
Restricts the trimming to dimension d.
Description
trimdata only ever removes elements; a dimension that is already at or below its target length stays as it is. With 'both' the cut is split between the two ends.
Its sibling paddata does the opposite and extends arrays, and resize does both.
Input arguments
A- Array to trim.
n, sz- Target length, or target size vector, with nonnegative integers.
'Side'- Which end to cut:
'trailing','leading'or'both'. 'Dimension'- Dimension or dimensions affected by
n.
Output arguments
B- The trimmed array. Dimensions already smaller than the target are left alone.
Example
x = 1:5;
trimdata(x, 3)
trimdata(x, 2, 'Side', 'leading')
trimdata(x, 9)
Output
ans = 1×3
1 2 3
ans = 1×2
4 5
ans = 1×5
1 2 3 4 5