ParaMonte MATLAB 3.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
index.m File Reference

Go to the source code of this file.

Functions

function index (in str, in pattern)
 Return the starting index of the first occurrence of the input scalar MATLAB string pattern in the input scalar MATLAB string str, otherwise, return 0 to indicate the lack of the pattern in the input str.
More...
 

Function Documentation

◆ index()

function index ( in  str,
in  pattern 
)

Return the starting index of the first occurrence of the input scalar MATLAB string pattern in the input scalar MATLAB string str, otherwise, return 0 to indicate the lack of the pattern in the input str.

This function partially replicates the functionality of the Fortran intrinsic function index().
This function uses the MATLAB intrinsic strfind() to achieve the goal. However, unlike strfind() it always returns a number such that the function can be directly used in string slicing.

Parameters
[in]str: The input scalar MATLAB string to be searched for the presence of the input pattern.
[in]pattern: The input scalar MATLAB string to be searched for within the input str.
Returns
loc : The output scalar MATLAB integer containing the location of the first occurrence of the input pattern in the input str or 0 if no such pattern exists.


Possible calling interfaces

loc = pm.str.index(str, pattern)


Example usage

1cd(fileparts(mfilename('fullpath'))); % Change working directory to source code directory.
2addpath('../../../'); % Add the ParaMonte library root directory to the search path.
3
4pm.matlab.show()
5pm.matlab.show('pm.str.index("paramonte", "")')
6 pm.str.index("paramonte", "")
7assert(pm.str.index("paramonte", "") == 0)
8
9pm.matlab.show()
10pm.matlab.show('pm.str.index("paramonte", "M")')
11 pm.str.index("paramonte", "M")
12assert(pm.str.index("paramonte", "M") == 0)
13
14pm.matlab.show()
15pm.matlab.show('pm.str.index("paramonte", "monte")')
16 pm.str.index("paramonte", "monte")
17assert(pm.str.index("paramonte", "monte") == 5)
function index(in array)
Given array(1 : n), return the array index indx(1 : n) such that array(indx) is in ascending order.
function root()
Return a scalar MATLAB string containing the root directory of the ParaMonte library package.
function show(in obj, in name, in hidden)
Display the components of an input MATLAB variable on MATLAB Console recursively.

Example output
1
2pm.str.index("paramonte", "")
3ans =
4 0
5
6pm.str.index("paramonte", "M")
7ans =
8 0
9
10pm.str.index("paramonte", "monte")
11ans =
12 5


Final Remarks


If you believe this algorithm or its documentation can be improved, we appreciate your contribution and help to edit this page's documentation and source file on GitHub.
For details on the naming abbreviations, see this page.
For details on the naming conventions, see this page.
This software is distributed under the MIT license with additional terms outlined below.

  1. If you use any parts or concepts from this library to any extent, please acknowledge the usage by citing the relevant publications of the ParaMonte library.
  2. If you regenerate any parts/ideas from this library in a programming environment other than those currently supported by this ParaMonte library (i.e., other than C, C++, Fortran, MATLAB, Python, R), please also ask the end users to cite this original ParaMonte library.

This software is available to the public under a highly permissive license.
Help us justify its continued development and maintenance by acknowledging its benefit to society, distributing it, and contributing to it.

Author:
Joshua Alexander Osborne, May 21 2024, 4:34 AM, University of Texas at Arlington
Fatemeh Bagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.
Amir Shahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin