我有一个数组,看起来像
test = {1,2,3};
我想确定一个整数是否属于数组。我尝试使用 ismember() 和 any() 但它们都返回了这个:
binary operator '==' not implemented for 'cell' by 'scalar' operations
我该怎么做?提前致谢
最佳答案
如果要检查矩阵中是否存在整数:
test = [1, 2, 3];
any (test == 2)
ans = 1
但是在您的问题中,您使用了元胞数组。在这种情况下,我会先将其转换为矩阵,然后执行相同的操作:
b = {1,2,3};
any (cell2mat (b) == 2)
ans = 1
关于arrays - 确定数组是否包含 Octave 音程中的特定整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36368881/