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 8799577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:21:41+00:00 2026-06-14T00:21:41+00:00

I have made an array of doubles and when I want to use the

  • 0

I have made an array of doubles and when I want to use the find command to search for the indices of specific values in the array, this yields an empty matrix which is not what I want. I assume the problem lies in the precision of the values and/or decimal places that are not shown in the readout of the array.

command:

peaks=find(y1==0.8236)

array readout:

y1 =

Columns 1 through 11

0.2000    0.5280    0.8224    0.4820    0.8239    0.4787    0.8235    0.4796    0.8236    0.4794    0.8236

Columns 12 through 20

0.4794    0.8236    0.4794    0.8236    0.4794    0.8236    0.4794    0.8236    0.4794

output:

peaks =

Empty matrix: 1-by-0

I tried using the command

format short

but I guess this only truncates the displayed values and not the actual values in the array.

How can I used the find command to give an array of indices?

  • 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-06-14T00:21:43+00:00Added an answer on June 14, 2026 at 12:21 am

    By default, each element of a numerical matrix in Matlab is stored using floating point double precision. As you surmise in the question format short and format long merely alter the displayed format, rather than the actual format of the numbers.

    So if y1 is created using something like y1 = rand(100, 1), and you want to find particular elements in y1 using find, you’ll need to know the exact value of the element you’re looking for to floating point double precision – which depending on your application is probably non-trivial. Certainly, peaks=find(y1==0.8236) will return the empty matrix if y1 only contains values like 0.823622378...

    So, how to get around this problem? It depends on your application. One approach is to truncate all the values in y1 to a given precision that you want to work in. Funnily enough, a SO matlab question on exactly this topic attracted two good answers about 12 hours ago, see here for more.

    If you do decide to go down this route, I would recommend something like this:

    a = 1e-4 %# Define level of precision
    y1Round = round((1/a) * y1); %# Round to appropriate precision, and leave y1 in integer form
    Index = find(y1Round == SomeValue); %# Perform the find operation
    

    Note that I use the find command with y1Round in integer form. This is because integers are stored exactly when using floating point double, so you won’t need to worry about floating point precision.

    An alternative approach to this problem would be to use find with some tolerance for error, for example:

    Index = find(abs(y1 - SomeValue) < Tolerance);
    

    Which path you choose is up to you. However, before adopting either of these approaches, I would have a good hard look at your application and see if it can be reformulated in some way such that you don’t need to search for specific “real” numbers from among a set of “reals”. That would be the most ideal outcome.

    EDIT: The code advocated in the other two answers to this question is neater than my second approach – so I’ve altered it accordingly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a 2d array grid made as int GRID[10][20]; What I want to
I have an array that I want on multiple pages, so I made it
I have an array made of: old_array=(color red shape circle vote 10) (alternating key/values)
I have made a String[] array by using String.split(.) . I am now trying
I have an array made of unlimited number of objects. These objects have the
I have made an app that gets an array of addresses from a web
PHP: I have made up a function that returns an array. I would like
So i have 2 classes, users and health readings. i made a array of
Let's say I have this $(document).ready(function() { var array = $.makeArray($('p')); $(array).appendTo(document.body); }); });
I have made an application for IPad in objective C. In this I am

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.