str2numendsWith
by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Text/Strs/Chars/Links
Introduced first in SolidGeometry 5.2, Creation date: 2022-02-26, Last change: 2025-09-15
returns the number that are part of in a string
Description
Many DICOM files or CT raw data files contain number that describe the order. This function extracts the numbers that are part of a string
See Also:
Example Illustration
Syntax
nn=str2numendsWith(ttt)
Input Parameter
ttt: | | string or cell list of strings |
Output Parameter
nn: | | rows with numbers for each string of the cell list |
Examples
a=dir('/Users/lueth/Desktop/imstack_imstack_300/*.raw') % find all raw files in a folder
ttt={a.name}' % create a cell list from the multiple results
str2numendsWith({a.name}'); nn=ans
Copyright 2022-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, str2numendsWith, is designed to extract numbers from strings, particularly useful for processing file names that contain numerical order information, such as DICOM or CT raw data files.
Input Parameters
- ttt: This can be a single string or a cell array of strings. The function processes each string to extract numbers.
Output
- nn: A matrix where each row corresponds to a string from the input. The row contains the numbers extracted from that string.
Algorithm Steps
- Check if the input
ttt is a cell array:
- If it is a cell array, initialize a matrix
nn with NaN values, having dimensions based on the number of strings and a fixed width of 100.
- Iterate over each string in the cell array:
- Call
str2numendsWith recursively for each string.
- Store the extracted numbers in the corresponding row of
nn.
- Track the maximum number of numbers found in any string to adjust the width of
nn.
- Trim
nn to the maximum width found.
- If
ttt is a single string:
- Initialize
nn as NaN.
- Use regular expressions to find sequences of digits in the string.
- If any numbers are found, convert them from strings to doubles and store them in
nn.
Example Usage
To use this function, you might first gather a list of file names using a command like dir in MATLAB, then pass the list of names to str2numendsWith to extract any numerical order information.
Algorithm explaination created using ChatGPT on 2025-08-19 01:38. (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