fprintfvec2

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Text/Strs/Chars/Links
Introduced first in SolidGeometry 4.6, Creation date: 2019-05-24, Last change: 2025-09-14

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



See Also: fprintfvec , str2codelines , sprintfvec

Example Illustration

 missing image of fprintfvec2 (f,s,X)

Syntax

fprintfvec2([f,s,X])

Input Parameter

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

Examples


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




Copyright 2019-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, fprintfvec2, is designed to print vectors in a format suitable for code generation. It is part of the SolidGeometry library and was introduced in version 4.6.

Input Parameters

Algorithm Steps

  1. The function begins by retrieving the input parameters using the getfuncparams function. It assigns default values if parameters are not provided.
  2. If only one argument is provided and it is numeric, it assigns this to X, sets s to '%d', and f to an empty string.
  3. If f is a character string, it assigns s to f, X to s, and f to an empty string.
  4. Two format strings, sfmt1 and sfmt2, are created using sprintf to format the output.
  5. The function then iterates over the rows and columns of X to print each element using the specified format. It uses sfmt1 for all but the last element in a row and sfmt2 for the last element.
  6. The output is enclosed in square brackets, and a semicolon is printed at the end if there are no output arguments.

Example

To print a matrix with three decimal places, you can use:

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

This will output:

[ 1.000, 2.000, 3.000; 4.000, 5.000, 6.000; ]
Algorithm explaination created using ChatGPT on 2025-08-18 23:57. (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