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
- fh: The file handle where the vector elements will be written. If not specified, it defaults to 1, which is the standard output (console).
- X: The vector whose elements are to be written. It can be a row or column vector.
- fs: The format string used to specify the number format for each element. The default format is
'%d'
, which is for integers.
Algorithm Steps
- The function begins by retrieving the input parameters using the
getfuncparams
function. It assigns default values if necessary.
- 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.
- The number of elements in the vector
X
is determined using numel(X)
.
- 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.
- 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
.
- 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