How to find an integer array in an array of cells in Matlab?

Suppose I have an array of cells containing an array of integer arrays. What is the best way to search for an array of cells for a particular array and return true if it exists, and false otherwise?

+4
source share
1 answer

You can use cellfun in combination with isequal :

For instance:

 cellArr = {[1 2 3],'xcxc',magic(5),1:3}; element = [1 2 3]; indexes = cellfun( @(x)isequal(x,element),cellArr); 

This will give you an array containing true in the cells that exist in this element. To check if an element exists at least once, simply use:

 any(indexes) 
+5
source

Source: https://habr.com/ru/post/1433324/


All Articles