8
我可以找一个值的位置,即45,在一个向量“数据”使用“==”运算符和“找到()”函数:Octave/Matlab:vectorising'=='operator?
data = [ 71 65 23 45 34 12 21 34 52 ];
value = 45;
find (data == value)
ans = 4
有没有办法做到对于不使用循环几个值相同,即我想获得[4 5 7]在一个单一的呼叫:
values = [ 45 34 21 ];
find (data == values)
error: mx_el_eq: nonconformant arguments (op1 is 1x9, op2 is 1x3)
error: evaluating argument list element number 1
error: evaluating argument list element number 1
实际上,这比我提议的方法快很多:'find(any(bsxfun(@eq,data,values'),1))''。使用'tic'' toc'我得到'ismember'比我的'bsxfun @ eq'方法快了x5倍**。做得好的比尔! – Shai 2012-12-03 09:04:24