Suppose I have a cell array containing an array of integer arrays. What is the best way to search the cell array for a specific array and return true if it exists and false otherwise?
You can use cellfun
combined with isequal
:
For example:
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 that contains true
in the cells that the element exists. In order to check whether the element exists at least once, just use:
any(indexes)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.