cellstrfind

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Text/Strs/Chars/Links
Introduced first in SolidGeometry 3.9, Creation date: 2017-06-25, Last change: 2025-09-14

returns the position of a string in a cell list of string

Description

developed before contains (Introduced in R2016b). Still more powerful, but slower

See Also: , cell2array

Example Illustration

 missing image of cellstrfind(cellstr,str)

Syntax

f=cellstrfind(cellstr,str)

Input Parameter

cellstr: cellstr
str: search string

Output Parameter

f: array of position for each cell elememt

Examples


x={'ax','ab','ac'}
cellstrfind(x,'c')




Copyright 2017-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 algorithm is designed to find the position of a specific string within a cell array of strings in MATLAB. It is part of the SG-Library and was created by Tim Lueth. Below is a detailed explanation of the algorithm and its parameters.

Input Parameters

Output Results

Algorithm Steps

  1. Check if the input cell array cellstr is a row vector. If not, transpose it to ensure it is a row vector and set a flag flp to true. Otherwise, set flp to false.
  2. Use the strfind function to find the position of the search string str within each element of the cell array. The result is transposed and converted to an array using cell2array.
  3. If the flp flag is true, transpose the result array f back to its original orientation.
  4. Replace any NaN values in the result array f with false, indicating that the search string was not found in those positions.

Example

Given a cell array x = {'ax', 'ab', 'ac'} and a search string 'c', the function cellstrfind(x, 'c') will return an array indicating the position of 'c' within each element of x.

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