Syntax
ostr=sprintfvec([f,s,X])
Input Parameter
f : | | file pointer; default is '' |
s : | | format string |
X : | | number |
Output Parameter
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
- f: A file pointer, default is an empty string ('').
- s: A format string, default is '%d'.
- X: A numeric matrix or vector.
Output Results
- ostr: The formatted output string.
- nstr: A secondary formatted string used internally.
Algorithm Steps
- 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
.
- Define format strings
sfmt1
, sfmt2
, and sfmt3
using the provided format string s
and a separator character sepchar
.
- Initialize
ostr
with '[ ' and nstr
as an empty string.
- Iterate over each element of the matrix
X
using nested loops. For each element, append the formatted string to ostr
and nstr
.
- 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:
sprintfvec('%.3f',[1 2 3; 4 5 6])
sprintfvec('%d',[1 2 3; 4 5 6])
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