fprintfvec

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

auxiliary fnct for writing ALL vector elements in ONE SINGLE row!



See Also: PosewriteAPD , fprintfvec2 , str2codelines , sprintfvec

Example Illustration

 missing image of fprintfvec (fh,X,fs)

Syntax

fprintfvec([fh,X,fs])

Input Parameter

fh: file handle
X: vector
fs: num format; default is '%d'

Examples


fprintfvec(1,[ 1 2 3 4 5 6 7 8; 1 2 3 4 5 6 7 8]*pi,'%.2f')
fprintfvec(1,[ 1 2 3 4 5 6 7 8; 1 2 3 4 5 6 7 8]*pi,'%d')




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)

The function fprintfvec is designed to write all elements of a vector in a single row to a specified file handle. It is part of the SolidGeometry library and was introduced in version 4.5.

Input Parameters

Algorithm Steps

  1. The function begins by retrieving the input parameters using the getfuncparams function. It assigns default values if necessary.
  2. It checks if fh is not a scalar and not a character. If so, it reassigns the parameters, assuming the user intended to use the default file handle.
  3. The number of elements in the vector X is determined using numel(X).
  4. Two format strings are created using sprintf: s1 for all elements except the last, and se for the last element, which includes a newline character.
  5. A loop iterates over each element of the vector X except the last, writing each element to the file handle fh using the format string s1.
  6. The last element of the vector is written using the format string se, which appends a newline character.

Example Usage

The function can be used to print a vector of numbers to the console or a file. For example:

fprintfvec(1, [1 2 3 4 5 6 7 8] * pi, '%.2f')

This will print the elements of the vector multiplied by pi to two decimal places.

Algorithm explaination created using ChatGPT on 2025-08-18 23:40. (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