repmatfill

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

fills an array with values or shortens the array



See Also: repmatfill

Example Illustration

 missing image of repmatfill(line,n,val)

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

Output

Algorithm Steps

  1. Determine the fill value val using the helper function getfuncparams. If val is not provided, use the last element of the input array line.
  2. Calculate the number of elements needed to reach the desired length n by subtracting the current number of elements in line from n.
  3. Extend the array line by appending the fill value val using the repmat function, which replicates the value as many times as needed.
  4. Truncate or extend the array to ensure it has exactly n elements by selecting the first n elements of the modified array.

Examples

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