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
- f: A file pointer. The default value is an empty string ('').
- s: A format string. The default is '%d'.
- X: A numeric matrix or vector.
Algorithm Steps
- The function begins by retrieving the input parameters using the
getfuncparams
function. It assigns default values if parameters are not provided.
- 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.
- If
f
is a character string, it assigns s
to f
, X
to s
, and f
to an empty string.
- Two format strings,
sfmt1
and sfmt2
, are created using sprintf
to format the output.
- 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.
- 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