by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Auxiliary function
Introduced first in SolidGeometry 5.4, Creation date: 2024-06-25, Last change: 2025-09-15
See Also: repmatfill
line=repmatfill(line,n,[val])
line: | [1 x m] array with values | |
n: | desired length | |
val: | value for fill up; default is line (end) |
line: | resulting line with length n |
repmatfill([1 2 3 4],3,0) % Shorten to length n
repmatfill([1 2 3 4],10) % Fill with last value to length n
repmatfill([1 2 3 4],10,0) % Fill with zeros to length n
This function, repmatfill, is designed to adjust the length of a given array, either by truncating it or by extending it with a specified value. It is part of the SolidGeometry library, version 5.4, and was created by Tim Lueth.
line.n.val using the helper function getfuncparams. If val is not provided, use the last element of the input array line.n by subtracting the current number of elements in line from n.line by appending the fill value val using the repmat function, which replicates the value as many times as needed.n elements by selecting the first n elements of the modified array.repmatfill([1 2 3 4], 3, 0): Shortens the array to a length of 3, resulting in [1 2 3].repmatfill([1 2 3 4], 10): Extends the array to a length of 10 by repeating the last value, resulting in [1 2 3 4 4 4 4 4 4 4].repmatfill([1 2 3 4], 10, 0): Extends the array to a length of 10 by filling with zeros, resulting in [1 2 3 4 0 0 0 0 0 0].