Function for 'does matrix contain value X?'

前端 未结 4 2067
天命终不由人
天命终不由人 2020-12-05 09:04

Is there a built in MATLAB function to find out if a matrix contains a certain value? (ala PHP\'s in_array())

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-05 09:44

    For floating point data, you can use the new ismembertol function, which computes set membership with a specified tolerance. This is similar to the ismemberf function found in the File Exchange except that it is now built-in to MATLAB. Example:

    >> pi_estimate = 3.14159;
    >> abs(pi_estimate - pi)
    ans =
       5.3590e-08
    >> tol = 1e-7;
    >> ismembertol(pi,pi_estimate,tol)
    ans =
         1
    

提交回复
热议问题