MATLAB Find Exact String in Cell Array Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report Cell arrays in MATLAB store data of various data types as a cell. These cells could contain data of different types but belong to the same array. Now, this article is focused on finding an exact string in a cell array in MATLAB. This can be done easily by using a combination of two MATLAB functions, the strcmp() and find() functions. Let us see how the same is done Syntax: s_log = strcmp(<array>,<string>) index = find(s_log) This will return a vector with indices of all string elements that exactly match the given string. The strcmp() function takes an array and a string as input. Then it compares the string with all values in the passed array and returns a logical array with 1 on matched cells and 0 on unmatched ones. See below to understand the same. Example 1: Matlab % MATLAB program for find Exact String in Cell Array % cell array arr = cell({'geeks', 'for', 'geeks'}); % String to be checked str = 'geeks'; % Getting a logical array from strcmp strcmp(arr,str) Output: This should return a vector [1 0 1] as the string str appears twice in the array arr on indices 1 and 3. Now, we can use the find function to get the indices of non-zero elements from this logical array, which will be the same as the indices of appearance of our 'str' string. Example 2: Matlab % MATLAB program arr = cell({'geeks', 'for', 'geeks'}); str = 'geeks'; ind_log = strcmp(arr,str); index = find(ind_log) Output: As it can be verified, the string 'geeks' appear on two indices 1 and 3, and the same result is given by our program. Let us take another example where we find the string 'devil' in a given cell array. Example 3: Matlab % MATLAB code for array arr = cell({'devil', 'is', 'not','home'}); % String str = 'devil'; % Finding logical array ind_log = strcmp(arr,str); %Finding indices using find functions index = find(ind_log); Output: Comment More infoAdvertise with us Next Article MATLAB Find Exact String in Cell Array O owl0223 Follow Improve Article Tags : Software Engineering Technical Scripter 2022 MATLAB Array-Programs Similar Reads How to extract numbers from cell array in MATLAB? In this article, we are going to discuss the extraction of numbers from the cell array with the help of regexp(), str2double(), cat(), and isletter() functions. What is a Cell Array? A cell array is nothing but a data type having indexed data containers called cells, where each cell contains any typ 3 min read Cell Arrays in MATLAB In MATLAB, cell arrays are a type of arrays which stores elements of different data types and sizes in different cells, or one could say that cell arrays allow users to store heterogeneous data into a single array. For example, let us create a cell array which holds the name and age of a person. Exa 2 min read Find Index of Cells Containing My String in MATLAB Cell Arrays in MATLAB are a type of array that store data in the form of cells. The benefit of using these cell arrays is that they can store data of different types as cells within a cell array only. In this article, we will see how to find a given string in a cell array. Firstly, we shall check wh 2 min read Characters and Strings in MATLAB In this article, we shall see how to deal with characters and Strings in MATLAB. A data type is an attribute/keyword that specifies the type of data that the object can hold: numeric data or text data. By default, MATLAB stores all numeric variables as double-precision floating-point values. Additio 4 min read How to Find Index of Element in Array in MATLAB? In MATLAB, the arrays are used to represent the information and data. You can use indexing to access the elements of the array. Â In MATLAB the array indexing starts from 1. To find the index of the element in the array, you can use the find() function. Using the find() function you can find the indi 4 min read Like