How do I find the closest value to a constant in an array

I have an array of floating numbers and I want to find a value in that array that is closest to a floating constant.     For example if I have the array 5.9, 2.8, 3.7, 5.8, 6.9, and if I have the constant 5.4, how would I find the closest value to 5.4 in the array, which in this case would be 5.8. The only approach I can think of is to subtract each value in the array from 5.8 and find the minimum value of an array which would be created from the differences. Is there a better approach?
Thank you.

Just be sure to take the absolute value of the difference and your proposed method is fine.

Similar Messages

  • Given a string, how do you find the numeric value in sparse ring?

    Situation: I receive the string value of the sparse ring, and a control reference to the same type of control, but not the control that sourced the string. How can I convert the string, into the actual numeric value of the ring? For example:
    Using the "VISA Select Event Type" ring (Functions -> Instrument I/O -> VISA -> Advanced -> Event -> Select Event Type.ctl), lets say I get the string "ServiceRequest" how do I convert that into 1073684491, the actual value of the ring?
    This is a rework of an existing function that worked fine with "normal" rings.
    Thanks.

    Unfortunately this method will not work, its a generic routine that must be able to take any ring, so I can't hardwire the cases to known outputs. And, of course, searching the array of Strings[] will just find me a useless index.
    My interm solution is this:
    1) pick a small, but likely range of possible values for the ring
    2) iterate through these values, assigning each one in turn to ring
    3) read the RingText property to see if it matches the passed string
    4) if it does, then exit. If it doesn't keep looping.
    5) if no value produces a matching string, declare defeat (raise an error or produce other output that indicates a match could not be found).
    The routine only runs in the UI so I am not too concerned about the time delay this method will i
    mpose, but I would greatly appreciate a smoother solution.
    Thanks for your suggestions.

  • How do I find the max value of scrollV in AS3?

    I used Ned's answer to get my 3 text fields scrolling together based on the value of one of them. Thanks Ned!
    The other two text fields scroll to match the 'parent' text field, but at the end - as you reach the last scroll position - the other two do not update and the 3 text fields are out of alignment. Its just at the end of the scroll. The rest of the scroll values align. I'm thinking if I can find the max scrollV value, I can force the other two to scroll one last time when that value is reached by the 'parent' text field.

    Thanks Rob! I knew it must be something available somewhere. That should allow me to do the needed calculations. Awesome.

  • How do you find the average value of all the data between two points on a single channel

    I am tring to calculate the average value of all the data points on a single plot between two seperate points
    I have attahced an illustration.
    Tim
    Solved!
    Go to Solution.
    Attachments:
    plot.jpg ‏173 KB

    Hey smoothdurban,
    I've seen Brad's code, and trust me, it's worth the effort to let him help you get it up and running - it's definitely the most ideal way to solve this problem.  However, as Brad said, there are multiple ways to tackle this - both interactive and programmatic - so in the meantime, I'll take a second to detail one of the interactive and sure-fire ways to find the average of data between two points on a single channel.
    We'll use"Flags."  Set up your VIEW graph exactly as you did on your original screenshot, using Band Cursors to approximate the beginning and ending X-values representing the range you want to examine.  Next:
    1. Click the "Set Flags" button () that is a part of your 2D Axis System.  Note that you can hold down the Shift button if you ever decide you want to do this on more than a single curve at one time.
    2. Select the "Flags: Copy Data Points" button that enables after Flags are set.
    3. This creates new channel(s) in the default (bold) group in the Data Portal that contains only the Flagged data.
    4. Select DIAdem ANALYSIS.
    5. Select Statistics » Descriptive Statistics.
    6. In the Channels input, select the newly created channel containing your Flagged Y-Data.
    7. Ensure that the Arithmetic Mean parameter is set.  You can preview the data and the result in the dialog before pressing OK to execute the calculation. 
    You may have noticed that in the Descriptive Statistics calculation, one of the parameters that you can set is the range of channel rows to operate on - so, if you know the row numbers of your beginning and ending X-values, you could just simply run the Descriptive Statistics calculation and use this parameter to operate on a row subset of your original channel instead of the entire channel.
    Derrick S.
    Product Manager
    NI DIAdem
    National Instruments

  • How do I use the Index Values property node with a multidimensional array.

    I am using a 2D array to store operator inputs on my front panel.  I only want to display one element to the operator at a time.  I am trying to use the Index Values property node to change the displayed element.  However, I can only get the Rows index to work.  How do I direct the Columns index as well?  The help says to use one per dimension.  I need clarification on what this is talking about.  I've tried adding a second element to the property node, 2 seperate property nodes, and diferent wiring techniques. (series, parallel)

    If you only wire up one of the inputs (col or row) what you get out is a 1D array of either the column or row. If you wire controls to both, then you will get one element out of the array. Getting a single element in a 2D array requires you to specify both a row and column.
    Message Edited by Dennis Knutson on 02-08-2007 08:34 AM
    Attachments:
    Index 2D Array.PNG ‏2 KB

  • How can i select the duplicate values

    Hi experts ,
    how can i find the duplicate values from the table. i want to display the all duplicate the rows.
    1. Table Structure :-
    CREATE TABLE CIF_MIGRATE
      LINE_NO        NUMBER(10),
      ACCT_NO        VARCHAR2(20 BYTE),
      BRANCH_ID      VARCHAR2(1 BYTE),
      CUSTOMER_NAME  VARCHAR2(100 BYTE),
      FATHER_NAME    VARCHAR2(100 BYTE),
      GF_NAME        VARCHAR2(100 BYTE),
      TOTAL          VARCHAR2(100 BYTE),
      STATUS         VARCHAR2(100 BYTE),
      CUSTOMER_TYPE  VARCHAR2(10 BYTE),
      GENDER         VARCHAR2(10 BYTE)
    ) 2. Sample Data:-
    SET DEFINE OFF;
    Insert into CIF_MIGRATE
       (LINE_NO, BRANCH_ID, CUSTOMER_NAME, CUSTOMER_TYPE)
    Values
       (72, '1', 'Addis Belay Construction Material Rental', 'C');
    Insert into CIF_MIGRATE
       (LINE_NO, BRANCH_ID, CUSTOMER_NAME, CUSTOMER_TYPE)
    Values
       (73, '1', 'Addis Belay Construction Material Rental', 'C');
    SET DEFINE OFF;
    Insert into CIF_MIGRATE
       (LINE_NO, BRANCH_ID, CUSTOMER_NAME, FATHER_NAME, CUSTOMER_TYPE, GENDER)
    Values
       (2869, '1', 'Abraham', 'Fiseha',
        'I', 'Male');
    Insert into CIF_MIGRATE
       (LINE_NO, BRANCH_ID, CUSTOMER_NAME, FATHER_NAME, CUSTOMER_TYPE, GENDER)
    Values
       (2870, '9', 'Abraham', 'Fiseha',
        'I', 'Male');
    Insert into CIF_MIGRATE
       (LINE_NO, BRANCH_ID, CUSTOMER_NAME, FATHER_NAME, GF_NAME, CUSTOMER_TYPE, GENDER)
    Values
       (2872, '9', 'Abraham', 'Baraki',
        'Medehniye', 'I', 'Female');
    Insert into CIF_MIGRATE
       (LINE_NO, BRANCH_ID, CUSTOMER_NAME, FATHER_NAME, GF_NAME, CUSTOMER_TYPE, GENDER)
    Values
       (2873, '1', 'Abraham', 'Geber kirstos',
        'gebre medihin', 'I', 'Female');
    Insert into CIF_MIGRATE
       (LINE_NO, BRANCH_ID, CUSTOMER_NAME, FATHER_NAME, GF_NAME, CUSTOMER_TYPE)
    Values
       (2874, '1', 'Abraham', 'Gebre egziabher',
        'Negussie', 'I');
    COMMIT;4. My requirement is i need display all the duplication customer
    CUSTOMER_NAME                                 FATHER_NAME,GF_NAME
    Addis Belay Construction Material Rental   
    Addis Belay Construction Material Rental
    Abraham                                              Fiseha
    Abraham                                              Fiseha5. I tried below query but i cant reach what i want exactly
    SELECT CUSTOMER_NAME,FATHER_NAME,GF_NAME
                               FROM CIF_MIGRATE
                          GROUP BY CUSTOMER_NAME,FATHER_NAME,GF_NAME
                             HAVING COUNT (*) > 1kindly suggest me the solution
    Thanks
    Arun

    Hi,
    You're on the right track using COUNT (*), but, for this job, you want the analytic COUNT, not the aggregate COUNT.
    "GROUP BY x, y, z" means that the result set will only contain 1 row for each distinct combination of x, y and z. Most aggregate functions (including COUNT) have analytic counterparts that get the same results without reducing the number of rows.
    Here's one way you can use the analytic COUNT function:
    WITH     got_cnt          AS
         SELECT    customer_name
         ,       father_name
         ,       gf_name
         ,       COUNT (*) OVER ( PARTITION BY  customer_name
                               ,                 father_name
                         ,           gf_name
                         )     AS cnt
         FROM       cif_migrate
    SELECT    customer_name
    ,       father_name
    ,       gf_name
    FROM       got_cnt
    WHERE       cnt     > 1
    ;PARTITION BY in analytic functions corresponds to GROUP BY in aggregate functions.

  • How to find the RGB Values of a Color for Hyperion

    When customizing your Hyperion forms, we come across situations where we need the exact RGB value of a given color. This article explains a simple technique to find the RGB values using MS Paint and the Calculator applications that come as standard applications with your operating system.
    Here are the steps to find the exact RGB value of a given color.
    1) View your Hyperion form using IE, scroll down until you see the color you want to find the RGB value and press the "Print Screen" button (in your keyboard).
    2) Open MS Paint and click Edit -> Paste or simply Ctrl+V. What you saw in the browser will be copied as a new untitled image.
    3) Select the Color Picker tool and click on an area that has the color you want to match.
    4) Now go to Edit Colors... option and click on the "Define Custom Colors >>" button. The color you picked will be selected on this palette. At the bottom right hand corner you will see the Red, Green and Blue values you need. Note down the R,G,B values (given in decimal).
    5) Now we need to find out the hexa-decimal values that correspond to those decimal values. This is where we use the simple Calculator. Open the Calculator application from Program -> Accessories. Switch to the scientific mode by clicking View ->Scientific.
    6) By default it will be in the decimal number mode. Enter the R value (238 in this example) and click on the Hex radio button. The corresponding hexa-decimal value (EE in this case) will be shown in the dial.
    The selected color in this case has the same value for R, G and B. (In fact, all shades of gray has the same values for R, G and B.) Therefore, the RGB value of the background color that we need is #eeeeee. Repeat step 6 to find out the hex value for the Green and Blue elements, if they are different.
    Tip:
    If you find it difficult to pick a color, zoom the image by pressing Ctrl+PageDown or using View -> Zoom -> Custom... option.

    These tips are to find the RGB color of HFM default row where row is text and text lines in data columns are also visible to business users as Yellow as an input cell. By applying the same RGB color you can apply the same color to your data cells or rows. This post shows how to identify color from any web view-able object.
    Regards,
    Manaf

  • How to find the nearlest value in 1-D array ?

    Hi.. everybody..
    I need to seperate the raw data(1-D) into 2 group of array by the center value and then make the average value in each array. But I also still have the problem about if the center value is not the same of some value in the 1-D array. I cannot use the split function.
    "How to find the nearlest value to the center point that I calculated, in the 1-D array ?"
    Thanks a lot for anybody help

    In a general sense, since I'm not sure what your data values are or how far away your calculated center is from the true value, I would do it one of two ways:
    1) Use a threshold value and scan the array until the threshold is reached (assumes constantly increasing values in the array).
    2) Use either a) round to nearest integer b) round to + Infinity (round up) or c) round to - infinity (round down). If you don't have decimal values, you'll have to devide the values by a power of 10.
    2006 Ultimate LabVIEW G-eek.

  • How can i find the value category code in CJVC

    Hi Gurus
    how can i find the value category code in CJVC and which tables its stored.can any one tell me.please please

    Read TPIK3 in an internal table, then search COEP-KSTAR in this table, with KSTAR between TPIK3-KSTRF and TPIK3-KSTRT, and other keys like Controlling Area and application/component (eg "PS" in project-system as in CJVC or "PM" in Maintenance as in IW33, multiple application use this table). You can also use a FM like PS_FIND_ACPOS_FOR_KSTAR.
    Regards,
    Raymond

  • How to use my findTheHighest method to find the highest value in my two dim

    I am going to create a 13row by 10 colume two dimensional array.
    how to use my findTheHighest method to find the highest value in my two dimensional array.
    .When i compile this program , i got those as following;
    "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsExce
    at TaxEvolution.findTheHighest(TaxEvolution.java:31)
    at TaxEvolutionClient.main(TaxEvolutionClient.java:25)"
    public class TaxEvolution{
    public double[][] salesTaxRates;
    public TaxEvolution()
      salesTaxRates = new double[13][10];
      fillProvinTaxRates();
    private void fillProvinTaxRates()
      for ( int row = 0; row < salesTaxRates.length; row++ )
        for ( int column = 0; column < salesTaxRates[row].length; column++ )
          salesTaxRates[row][column]= (int)(Math.random()*5000) + 1;
    public double findTheHighest()
        double highest = salesTaxRates[0][0];
        for ( int row = 0; row <= salesTaxRates.length; row++ )
          for ( int column = 0; column <= salesTaxRates[row].length; column++ )
             if ( salesTaxRates[row][column] >= highest )
                   highest = salesTaxRates[row][column];
        return highest;   
    public double[][] arrayTaxEvolution()
      double[][] returnTaxRates = new double[13][10];
      for ( int row = 0; row < salesTaxRates.length; row++ )
        for ( int column = 0; column < salesTaxRates[row].length; column++ )
          returnTaxRates = salesTaxRates;
      return returnTaxRates;
    public class TaxEvolutionClient{
    public static void main( String[] args ){
      TaxEvolution protaxRateList = new TaxEvolution();
      double[][] taxRateList = protaxRateList.arrayTaxEvolution();
        for ( int i = 0; i < taxRateList.length; i++ )
          for ( int j = 0; j < taxRateList[0].length; j++ )
            System.out.print( taxRateList[i][j] + "\t" );               
            System.out.print( protaxRateList.findTheHighest + "\t" );
    }

    Multiposted
    http://forum.java.sun.com/thread.jspa?threadID=699057&tstart=0

  • How to find the FND_PROFILE.VALUE(ORG_ID) in custom apex schema

    Hi,
    How to find the FND_PROFILE.VALUE('ORG_ID') from dual in custom schema......
    Actually I have integrated Apex 4.2 version with EBS r12
    select FND_PROFILE.VALUE('ORG_ID') from dual ; in apps schema I m getting 198 value
    but the same query(select  apps.FND_PROFILE.VALUE('ORG_ID') from dual ) in custom schema (XXCVBB) returning null value..
    Is there  any pre steps I have to do...
    kindly provide the useful inputs to retrieve the profile value..........
    Regards,
    Pavan

    Hi,
    fnd_profile.value('ORG_ID'); will fetch you value only if there is a organization assigned to any application [or only if its  a single Org], being it custom application you should have used set policy context or mo_global.init to populate the global temporary table which will hold all the Org's which that specific user has access too.
    in your custom code use MO_GLOBAL.SET_POLICY_CONTEXT('S','ORG ID WHICH YOU NEED TO SET');
    after setting the policy context, you should be able to see value from fnd_profile.value('ORG_ID');
    Hope this Helps!!
    MO_GLOBAL.SET_POLICY_CONTEXT
    This procedure has two parameters
    p_access_mode
    Pass a value "S" in case you want your current session to work against Single ORG_ID
    Pass a value of "M" in case you want your current session to work against multiple ORG_ID's
    p_org_id
    Only applicable if p_access_mode is passed value of "S"
    MO_GLOBAL.INIT
    Purpose of mo_global.init :-
    It will check if new Multi Org Security Profile is set, to decide if new Security Profile method will be used.
    If the new MO security profile is set, then mo_global.init inserts one record, for each Organization in Org Hierarchy, in table mo_glob_org_access_tmp
    Regards,
    Yuvaraj

  • How to find the ASCII value of '  ?

    how to find the ASCII value of ' using ASCII Function in SQL??
    while i am trying this using syntax ASCII(''') the query is terminating at the second one

    Lokanath Giri wrote:
    For your validation check this link
    http://www.techonthenet.com/ascii/chart.php
    Please don't just refer people to other non-oracle websites when the answer is so simple to give here as others have already done.

  • How to find the maximum value among four fields in a single record

    Hi Gems...
    I have a record in which there are 4 currency fields.
    Now i would like to know the maximum of these 4 fields.
    I tried with Max functions in which i put all the 4 values...but it is showing error like ") is missing" though it is there.
    Can we insert more than 2 values in Max function?
    Or else is there any other option to find the max value among the 4 values which lies in a single record
    Thanks
    Jiten

    Hi Anil,
    Say suppose i have a single record in which 4 premiums of a particular bond exists.
    for eg:
    Prem1      Prem2        Prem3          Prem4
    129000.00      388000.00   228000.00   14800.00
    Now this is a single record for a particular bond ... now i need to calculate the max value among these 4 premiums.
    How would we proceed to achieve this?
    Regards
    Jiten
    Edited by: Jitendra Yuddandi on Feb 3, 2009 1:04 PM

  • How to find the ASCII value for an alphabet.

    How to find the ASCII value for an alphabet.

    How can I get Ascii value of any letter
    How can I get Ascii value of any letter.  Is there any function?
    This is how you do it : 
    report demtest.
    data : c.
    field-symbols : <n> type x.
    data : rn type i.
    c = 'A'.
    assign c to <n> casting.
    move <n> to rn.
    write rn.
    This will convert 'A' to 65.
    Tom Demuyt
    How to convert ascii value to character.
    If I give input as 65 (ascill value) I want display 'A'.
    Below logic is for convert from character to ascii value , now I want to know how to convert ascii value to character.
    Naveen
    report demtest.
    *going from A to 65
    data : c value 'A'.
    field-symbols : <n> type x.
    data : rn type i.
    assign c to <n> casting.
    move <n> to rn.
    write rn.
    *going from 66 to B
    data : i type i value 66.
    data : x type x.
    field-symbols : <fc> type c.
    move i to x.
    assign x to <fc> casting type c.
    move <fc> to c.
    write c.

  • How to find the PREVIOUS value of a non-DB item?

    I want to do a simple thing but found it impossible.
    I want to find the previous value of a non-DB item in a form.
    I tried creating a text item and populating it using PRE-TEXT-ITEM but that does not work.
    WHEN-VALIDATE-ITEM does not work either because WVI fires only after item value has changed.
    Any suggestions will be greatly appreciated.
    Edited by: Channa on Apr 2, 2010 4:34 AM

    Channa wrote:
    I want to do a simple thing but found it impossible.
    I want to find the previous value of a non-DB item in a form.
    I tried creating a text item and populating it using PRE-TEXT-ITEM but that does not work.
    WHEN-VALIDATE-ITEM does not work either because WVI fires only after item value has changed.
    Any suggestions will be greatly appreciated.
    Edited by: Channa on Apr 2, 2010 4:34 AMPlease make it clear what is your requirement then possibly we can provide you a better answer
    You can use Global variables for to store old values also on Post-query populate a value in separate field or Parameter

Maybe you are looking for

  • ITunes 10.1.2 upgrade on  Win XP Pro SP3 Kills Internet access

    The latest iTunes 10.1.2 install on my Win XP Pro SP3 system kills my Internet access. Internet status shows that I'm connected but Internet Explorer and Firefox can't connect to the server. Running Win XP Pro SP3 with all MS updates applied on a Dua

  • Physical Standby Database (Protection Mode)?!!

    Hi, I have configured a physical standby database to use Real-time Apply, but i noticed that the protection mode of the database has been changed from "Maximum Performance" to ''Maximum Availability".. log_archive_dest_3='service=phystby OPTIONAL LGW

  • Clickable Overlay MediaElement via VAST

    I am in the process of modifying the VAST system and have everything working for the most part, but I ran into an issue in regards to non-linear overlay ads.  What is the best approach to making smaller VAST image overlays clickable?  It seems dificu

  • Displaying Graph in Viewer

    Hi, I want to Display the Graph to the right side of the table. By default it is displayed at the Bottom. How can I achieve this. Any help will be Appreciated.And If I click on Printable Page the Graph is not getting Displayed. Why? Thanks & Regards,

  • I have tried to open Photoshop CS5 andante a message saying I need to download JavaSE6. I can't find where to get JavaSE6

    I have just installed Yosemite onto my iMac. When I try to open Photoshop CS5 I get a message that I need to download JavaSE6. When I click onto the get more information tab the screen goes blank.