Syntax
vec=number2vec(s)
Input Parameter
s : | | string or integer scalar |
Output Parameter
Examples
number2vec(123)
number2vec('123')
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, number2vec
, converts a number into a vector of its individual digits. It is part of the SolidGeometry library and was introduced in version 4.5.
Input Parameters
- s: This can be either a string or an integer scalar. It represents the number that will be converted into a vector of digits.
Output Results
- vec: A vector of integers, where each element is a digit from the input number.
Algorithm Steps
- Check if the input
s
is numeric. If it is, convert it to a string using num2str
.
- Determine the number of elements in the string representation of
s
using numel
.
- Initialize a zero vector
vec
with the same number of elements as the string.
- Iterate over each character in the string:
- Convert each character to a double using
str2double
and assign it to the corresponding position in vec
.
Example Usage
To convert the number 123 into a vector of digits, you can call the function as follows:
number2vec(123)
Alternatively, if the number is provided as a string:
number2vec('123')
Algorithm explaination created using ChatGPT on 2025-08-18 22:16. (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