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