Syntax
line=repmatfill(line,n,[val])
Input Parameter
line : | | [1 x m] array with values |
n : | | desired length |
val : | | value for fill up; default is line (end) |
Output Parameter
line : | | resulting line with length n |
Examples
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
Copyright 2024-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth
Algorithm (Workflow)
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.
Input Parameters
- line: A 1-dimensional array of size [1 x m] containing the initial values.
- n: The desired length of the output array.
- val (optional): The value used to fill the array if it needs to be extended. If not provided, the default is the last element of the input array
line
.
Output
- line: The resulting array, adjusted to the specified length
n
.
Algorithm Steps
- Determine the fill value
val
using the helper function getfuncparams
. If val
is not provided, use the last element of the input array line
.
- Calculate the number of elements needed to reach the desired length
n
by subtracting the current number of elements in line
from n
.
- Extend the array
line
by appending the fill value val
using the repmat
function, which replicates the value as many times as needed.
- Truncate or extend the array to ensure it has exactly
n
elements by selecting the first n
elements of the modified array.
Examples
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]
.
Algorithm explaination created using ChatGPT on 2025-08-18 23:14. (Please note: No guarantee for the correctness of this explanation)
Last html export of this page out of FM database by TL: 2025-09-21