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
- cellstr: A cell array of strings. This is the list in which the algorithm searches for the specified string.
- str: The search string. This is the string that the algorithm looks for within the cell array.
Output Results
- f: An array indicating the position of the search string within each element of the cell array. If the string is not found, the position is marked as false.
Algorithm Steps
- 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.
- 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
.
- If the
flp
flag is true, transpose the result array f
back to its original orientation.
- 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