paddata
Pads an array with extra values up to a given size.
Category: Language Fundamentals > Matrices and Arrays
Syntax
B = paddata(A, len)
Pads the first non-singleton dimension to length len, with zeros at the end.
B = paddata(A, sz)
Pads to the full size sz.
B = paddata(___, Name, Value)
Options: 'Dimension', 'FillValue', 'Pattern', 'Side'.
Description
It is used to make vectors of different lengths the same length before stacking them into a matrix. Unlike resize, paddata only adds: an array that is already larger than the target is left alone, never cropped.
For cell arrays the new cells are empty.
Input arguments
A- Numeric array or cell array.
len, sz- Target length, or target size vector. Never shrinks the array.
'FillValue'- Value used for the new elements (default 0).
'Side''trailing'(default) adds at the end,'leading'at the start,'both'on both sides.'Pattern'- How to generate padding:
'constant','edge','circular','flip'or'reflect'.
Output arguments
B- Array padded to at least the requested size. If
Ais already large enough it is returned unchanged.
Example
paddata([1 2 3], 5)
paddata([1 2 3], 5, 'Side', 'leading')
paddata([1 2; 3 4], 3, 'FillValue', -1)
Output
ans = 1×5
1 2 3 0 0
ans = 1×5
0 0 1 2 3
ans = 3×2
1 2
3 4
-1 -1