padsequences — Pad or truncate numeric sequence cell arrays.
padsequences(sequences, paddingDim) pads or truncates numeric sequences stored in a cell array along the requested dimension.
Syntax
Y = padsequences(sequences, paddingDim)
Y = padsequences(sequences, paddingDim, Name, Value)How padsequences works
sequencesmust be a cell array of numeric scalar/vector/tensor sequences.paddingDimis a required positive integer dimension.PaddingDirectionacceptsleft,right, orboth; the default isright.Lengthacceptslongest,shortest, or a positive integer.PaddingValueaccepts a finite numeric scalar and defaults to0.UniformOutputdefaults totrueand stacks padded sequences into a numeric tensor;falsepreserves the input cell shape.
GPU memory and residency
padsequences materializes host sequence tensors in this slice; provider-resident sequence padding remains future GPU work.
Examples
Right Pad Sequences
Y = padsequences({[1 2], 3}, 2, 'PaddingValue', -1)Expected output:
A numeric tensor with right-padded row sequences.Preserve Cell Shape
C = padsequences({[1 2 3], [4 5]}, 2, 'Length', 2, 'PaddingDirection', 'left', 'UniformOutput', false)Expected output:
A cell array whose first sequence keeps the tail `[2 3]`.Using padsequences with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how padsequences changes the result.
Run a small padsequences example, explain the result, then change one input and compare the output.
Related Deep Learning functions
adamupdate · analyzeNetwork · bilstmLayer · classificationLayer · combvec · convolution1dLayer · crossentropy · dlarray · dlfeval · dlgradient · dlnetwork · dlupdate · eluLayer · exportONNXNetwork · featureInputLayer · forward · fullyConnectedLayer · globalAveragePooling1dLayer · layerGraph · layerNormalizationLayer · lstmLayer · regressionLayer · reluLayer · sequenceInputLayer · softmaxLayer · trainingOptions · trainnet · trainNetwork
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.