Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我有一个包含整数数组数组的元胞数组。在元胞数组中搜索特定数组并在存在时返回 true 否则返回 false 的最佳方法是什么?
您可以cellfun结合使用isequal:
cellfun
isequal
例如:
cellArr = {[1 2 3],'xcxc',magic(5),1:3}; element = [1 2 3]; indexes = cellfun( @(x)isequal(x,element),cellArr);
这将为您提供一个数组,其中包含true该元素存在的单元格。为了检查元素是否至少存在一次,只需使用:
true
any(indexes)