sprintfvec

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Text/Strs/Chars/Links
Introduced first in SolidGeometry 4.9, Creation date: 2020-03-21, Last change: 2025-09-14

prints vectors in a way that it can used in code generation



See Also: fprintfvec , fprintfvec2 , str2codelines

Example Illustration

 missing image of sprintfvec(f,s,X)

Syntax

ostr=sprintfvec([f,s,X])

Input Parameter

f: file pointer; default is ''
s: format string
X: number

Output Parameter

ostr: output string

Examples


sprintfvec('%.3f',[1 2 3; 4 5 6])
sprintfvec('%d',[1 2 3; 4 5 6])




Copyright 2020-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, sprintfvec, is designed to format and print vectors in a way that can be used for code generation. It is part of the SolidGeometry library and was introduced in version 4.9.

Input Parameters

Output Results

Algorithm Steps

  1. Retrieve input parameters using getfuncparams function. If only one argument is provided and it is numeric, assign it to X and set s to '%d'. If f is a character, swap s and X.
  2. Define format strings sfmt1, sfmt2, and sfmt3 using the provided format string s and a separator character sepchar.
  3. Initialize ostr with '[ ' and nstr as an empty string.
  4. Iterate over each element of the matrix X using nested loops. For each element, append the formatted string to ostr and nstr.
  5. Remove the last separator from ostr and close the bracket with ']' to complete the formatted string.

Example Usage

Examples of how to use the function:

Algorithm explaination created using ChatGPT on 2025-08-19 08:00. (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