Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 509607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:01:42+00:00 2026-05-13T07:01:42+00:00

Is there a built in MATLAB function to find out if a matrix contains

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T07:01:42+00:00Added an answer on May 13, 2026 at 7:01 am

    Many ways to do this. ismember is the first that comes to mind, since it is a set membership action you wish to take. Thus

    X = primes(20);
    ismember([15 17],X)
    ans =
          0    1
    

    Since 15 is not prime, but 17 is, ismember has done its job well here.

    Of course, find (or any) will also work. But these are not vectorized in the sense that ismember was. We can test to see if 15 is in the set represented by X, but to test both of those numbers will take a loop, or successive tests.

    ~isempty(find(X == 15))
    ~isempty(find(X == 17))
    

    or,

    any(X == 15)
    any(X == 17)
    

    Finally, I would point out that tests for exact values are dangerous if the numbers may be true floats. Tests against integer values as I have shown are easy. But tests against floating point numbers should usually employ a tolerance.

    tol = 10*eps;
    any(abs(X - 3.1415926535897932384) <= tol)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a built-in php function or an easy way to insert an element
Is there any built in MATLAB command that stretches out a multidimensional array into
Is there a built-in function that converts a datetime.date object into a datetime.datetime object
I originally intended to use MATLAB to tackle this problem but the in-built function
Is there a way to get the mex file for a built-in MATLAB m-
I have noticed that matlab does some matrix function really fast for example adding
Is there any built-in functions in MATLAB that would statistically extend a sequence of
I'm looking for a built-in Matlab function that sums two polynomial. Example: p1(x) and
I have read MATLAB's info on multi-threading and how it is in-built in certain
I have read MATLAB's info on multi-threading and how it is in-built in certain

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.