Find Index for max value of array

I can use arrayMax to get the max value for a small array, but I need to get which index the max value is located. That will determine which page the user goes to next. Here is my code:
array:
<cfset arrAverages[1]="#qryFairness.fairness#"/>
<cfset arrAverages[2]="#qryHonesty.honesty#"/>
<cfset arrAverages[3]="#qryCompassion.compassion#"/>
<cfset arrAverages[4]="#qrySelfControl.SelfControl#"/>
<cfset arrAverages[5]="#qryMoralConcern.MoralConcern#"/>
These values are gathered from querying values stored in a table.
I can get the max value in the array easily by:
<cfdump var="#arrayMax(arrAverages)#">
What I can't figure out is how to get the row in this array where that max value is located. It seems like it would be so simple, but nothing I have tried has worked.
Thanks,
Richard

rking1966 wrote:
I can use arrayMax to get the max value for a small array, but I need to get which index the max value is located. That will determine which page the user goes to next. Here is my code:
array:
<cfset arrAverages[1]="#qryFairness.fairness#"/>
<cfset arrAverages[2]="#qryHonesty.honesty#"/>
<cfset arrAverages[3]="#qryCompassion.compassion#"/>
<cfset arrAverages[4]="#qrySelfControl.SelfControl#"/>
<cfset arrAverages[5]="#qryMoralConcern.MoralConcern#"/>
These values are gathered from querying values stored in a table.
I can get the max value in the array easily by:
<cfdump var="#arrayMax(arrAverages)#">
What I can't figure out is how to get the row in this array where that max value is located. It seems like it would be so simple, but nothing I have tried has worked.
You can find it in one line of code! Here is an example:
<cfset testArr[1]=-183>
<cfset testArr[2]=79>
<cfset testArr[3]=6>
Max.:  <cfoutput>#arraymax(testArr)#</cfoutput><br>
Index of max.: <cfoutput>#arrayfindNocase(testArr, arraymax(testArr))#</cfoutput>

Similar Messages

  • Find the 20 max values

    Say i have an array of 40 doubles. How can i find the 20 maximum values from my array?

    Do you know how to sort?
    Can you use the Java APIs?ha ha..
    yeah.. sort the array and pick the 20.
    Or if you write something like a bubble sort, let the outer loop executing half times as the usual..

  • How to find index and minimium value in ArrayList?

    Hi,
    I got an ArrayList numbers that contains the following....
    [4,5,4,3,3,4,4,3,6,5]
    How do I go through the ArrayList numbers, such that I can get the
    minimum value and it's index number in the arrayList?
    For example, the above arrayList got three min number of 3, I will
    get either one of the 3 and also get it's index of 3, 4 or 7.
    The ArrayList number can have another number of records inside it.
    Please advice.
    Thank you.

    Please do not cross post:
    http://forum.java.sun.com/thread.jsp?thread=471261&forum=31&message=2177088
    Besides, I would not forcibly qualify this topic as an advanced one.

  • SQL Query for max values!!

    Hi to all,
    I have four tables
    Tbl_one
    Tbl_two
    Tbl_three
    Tbl_four
    the relation between these tables is
    Tbl_one.SEQ = Tbl_two.SEQ)
    and tbl_two.case_SEQ = Tbl_four.SEQ
    AND Tbl_two.ORDER_SEQ = tbl_three.SEQ))
    I want a query like this
    Select tbl_one.com_name, tbl_three.test_date,tbl_four.order_date
    from Tbl_one,Tbl_two,Tbl_three,Tbl_four
    where Tbl_one.SEQ = Tbl_two.SEQ)
    and tbl_two.case_SEQ = Tbl_four.SEQ
    AND Tbl_two.ORDER_SEQ = tbl_three.SEQ))
    and tbl_three.test_date in (select max(test_date) from tbl_three)
    and tbl_four.order_date in select(max(order_date from tbl_for)
    and max(test_date)> Max(order_date)
    any way it is possible?
    the real problem is there are multiple test_dates and
    multiple order_date for same seq in tbl_one.seq.
    eg: -
    name (indian) which has three or more test_date and each test_date have more than one order_date
    indian (name) 01/01/2009(test_date) has ---- 01/10/2009, 01/20/2009 and 01/21/2009) order_dates
    india(name) 02/02/2009 (test_date) has ----- 02/10/2009, 02/20/2009 and 02/30/2009 (order_dates)
    india(name) 03/03/2009 test_date has ----- 03/10/2009, 03/20/2009 , 03/25/2009 (order_dates).
    japan has the same situation and so on
    what i wanted from the query is
    max(test_date)= 03/03/2009 > max(order_date)=03/25/2009
    ans: -
    name
    india(name) 03/03/2009 (test_date) 03/25/2009(order_date)
    etc. etc . etc.
    thanks!!
    Edited by: pl/sql baby on Mar 24, 2009 10:45 AM
    Edited by: pl/sql baby on Mar 24, 2009 10:47 AM
    Edited by: pl/sql baby on Mar 24, 2009 10:51 AM
    Edited by: pl/sql baby on Mar 24, 2009 10:57 AM

    Please use tags either side of code / data (to preserve the formatting and spacing).
    I don't understand your requirement... 03/03/2009 is not greater than 03/25/2009 ?
    Could you please be clearer in your input/output samples and explain more about how to generate the output?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Why Optimizer Skipping PK index for more values of IN statement?

    Hi
    Oracle10g R2
    I got a simple table of 2 columns. total Rows 440
    1st column 'c1' of datatype number is primary key.
    when i execute query with IN statement contain 6 values to compare with c1
    where c1 IN (1270030,4474731,5530840,1295700,343266,44423434)
    it use index and when i use 7 and more then 7 values in IN statement it bypass index.
    Experts please advise is it Oracle default behaviour due to my less rows 440 only , or I need to do something more to ensure index base scan?
    Thank

    1) Oracle does I/O by blocks and not by rows. A decision on FTS or not depends (not only) on the number of blocks and not rows. If it's not a IOT table please verify index clustering factor.
    2) If table blocks are less (under HWM) than DB_FILE_MULTIBLOCK_READ_COUNT (a single I/O call), a FTS may be cheaper.
    3) You can always look under the hood with 10053 event and try to understand CBO behavior.
    Regards,
    Luis Marques

  • How to find the second max value

    i have a table named customer, which have a column named salary ,how can i find the customer number which have the second largest salary.

    this example might be of help.
    SQL> select empno, ename, sal, job,
      2         rank() over (partition by job order by sal desc) rank
      3    from emp;
         EMPNO ENAME             SAL JOB             RANK
          7902 FORD             3000 ANALYST            1
          7788 SCOTT            3000 ANALYST            1
          7934 MILLER           1300 CLERK              1
          7876 ADAMS            1100 CLERK              2
          7900 JAMES             950 CLERK              3
          7369 SMITH             800 CLERK              4
          7566 JONES            2975 MANAGER            1
          7698 BLAKE            2850 MANAGER            2
          7782 CLARK            2450 MANAGER            3
          7839 KING             5000 PRESIDENT          1
          7499 ALLEN            1600 SALESMAN           1
         EMPNO ENAME             SAL JOB             RANK
          7844 TURNER           1500 SALESMAN           2
          7521 WARD             1250 SALESMAN           3
          7654 MARTIN           1250 SALESMAN           3
    14 rows selected.
    SQL> select e.empno, e.ename, e.sal, e.job
      2    from (select empno, ename, sal, job,
      3                 rank() over (partition by job order by sal desc) rank
      4            from emp) e
      5   where e.rank = 2;
         EMPNO ENAME             SAL JOB
          7876 ADAMS            1100 CLERK
          7698 BLAKE            2850 MANAGER
          7844 TURNER           1500 SALESMAN

  • Best Way to find min and max

    Hi
    I wish to know is there any better way to get min(zseq) from a query statement?
    I have data as :
    00010 10 1 10/10/2006   - need to get tihs date (min)
    00010 10 2 12/10/2006
    00010  10 3 15/10/2006 - need to get this date(max-1)
    00010 10 4 18/10/2006 - need to get this date (max)
    My query :
    SELECT ZCDD FROM ZVI2D INTO S_1ST_ZCDD
          WHERE ZVBELN = WA_OUTPUT_ALL-VBELN AND ZPOSNR = WA_OUTPUT_ALL-POSNR
            AND ZSEQ IN ( SELECT MIN( ZSEQ ) FROM ZVI2D WHERE ZVBELN = WA_OUTPUT_ALL-VBELN AND ZPOSNR = WA_OUTPUT_ALL-POSNR ).
             AND ZDATUM = WA_OUTPUT_ALL-ZDATUM ).
        ENDSELECT
    I will reward points if you are able to give a good uggestion. Thanks.

    i think you can get max and min from the select query itself just check my previous posting for the min. But i dont think you can get the second maximum value from the select query. For that you have to store the data in itab and sort that by descending read thae table itab with index 1(max) and index 2(second largest) and last for min.
    suppose you have data inyour itab.
    data : lin type i.
    sort itab by <field name> descending.
    read table itab index 1."for max value.
    write : / itab-<field>.
    read table itab index 2."second largest.
    write : / itab-<field>.
    describe table itab lines lin.
    read table itab index lin.
    write :  / itab-<field>.
    regards
    shiba dutta

  • Can we create an index for a list of itmes in a single object?

    Can we create an index for multiple values in a single object. We have an object Order that contains list of items. I like to get all orders for a specific item. I want to create an index to speed up the query. Is it possible? What are the other alternatives?
    My Order object is as follows:
    Orders
    Item List
    Shipping Address
    Example:
    Order 1
    i1, i2, i3, i4
    123 some way, city, 12345
    Order 2
    i2, i3
    333 some other way, city2, 33333
    order 3
    i2, i4, i7
    My search would be, give me all orders that has item i2. It should return Order 1, Order 2 and Order 3.
    Thanks

    Hi,
    I think that this will work ...
    ValueExtractor extractor= new ReflectionExtractor("getItemList");
    cache.addIndex(extractor, true, null);
    Set setKeys = cache.keySet(new EqualsFilter(extractor, i2));
    In this case, the Collection value extracted by the ValueExtractor is treated as a Collection of contained attributes when the index is created.

  • Shifting positions of values in arrays

    I need to replicate some functionality in existing IDL (Interactive Data Language) code. This language has some very high level constructs for moving values in arrays. This statement:
    shifted_array = shift(my_array, xshift, yshift)shift all the values in my_array in the x direction by xshift and all the values in the y direction by yshift (and wraps the values around) and puts them in shifted_array.
    How would I best implement this in Java? That is, do it row-by-row / column-by-column / element-element? If so, does anybody have such code already? If not, is there some 'higher-level' way to do this? or use some other data structure?
    Message was edited by:
    allelopath

    Most of the functionality you describe is in
    arraycopy(Object, int, Object, int, int) - Static method in class java.lang.System
    Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination array.
    You need to handle the wraparound.

  • How to find indexes in sql tables

    Hi i need help for how to find the indexes for the sql tables.I had some tables in sql 2005 and i need to find indexes for that tables.Can anyone will help in this isssue.

    I think you can use one of the built-in db functions ... (but it depends upon which database you're using)
    in sql server:
    sp_helpindex tablename

  • Find more than one min and max in 2D array contain 0 rows

    Hi
    I have a 2D array and I would like to find the max and min elements between series of 0s. As you can see in the picture If I remove all 0s from the array and use the max and min function then I will have just one min and one max but I need to find min and max after every 0 rows so you can see from the picture ( just as an example) I will have 3 min and 3 max numbers. Would you please help me with this code. Do you now any algorithm that can find min and max between 0s?
    I have also attached my code to remove 0s and then search for max and min numbers but as I mentioned I need min and max for every part
    Many thanks
    Attachments:
    2.jpg ‏82 KB
    3.jpg ‏27 KB

    Thanks altenbach
    I have attached the vi to this post. I would really apperciate if you help me with this example. The min values should be 100, 1500 and 4000 and the max values should be 1200,2600,5400 so as u mentioned the output should be this 2D array 
    100,1200
    1500,2600
    4000,5400
    Attachments:
    new.vi ‏6 KB

  • Calculating min and max value from number array

    I have array which is having return type Number.i want to calculate min and max value of this array..try to help asap..
    Thanks
    dhanu

    hi there,
    public class MinMax {
         int arr[]= { 27, 3, 42, 18, 243, -43, 6, -8 };
         int min, max;
         public MinMax() {
    // it's very bad way to do it.
    //          min=99999;
    //          max=-99999;
    // this must be as following
                    min = max = arr[0];
              search();
              System.out.println("The minimum value is: "+min);
              System.out.println("The maximum value is: "+max);
         private void search() {
    // and here we can search from <1> index instead of <0>
              for (int j=1; j<arr.length; j++) {
                   if (arr[j]<min) {
                        min=arr[j];
                   else if (arr[j]>max) {
                        max=arr[j];
         public static void main(String args[]) {
              new MinMax();
    there is a bug in the supplied code. Your homework is
    to figure out what it is without posting another
    message for help with your homework.well, i think it's a tragedy :(

  • Using a For Loop Index for Array Element Number?

    Hi.  Thanks in advance for the help.  I can't seem to find what I want to do here using the search function... probably because I don't know how to frame the question appropriately.  Ignore the title to this post cause it's probably wrong vocabulary for what I want to do.
    Here's the situation:
    I have a 2D array where the first column is the X data and each subsequent column is Y data (call it Y1...Yn).  The n-value varies from run to run (some runs have 4 columns of data, some have 20), but that is easily gathered when reading the data file.  I need to perform a number of operations on each set of data, the least of which is smoothing the data and graphing it, so I'm limiting my discussion to these 2 operations.
    What I want is a for loop structure where the indexing of the loop tracks the Y1...Yn columns, grabs each column for the iteration, performs the relevant analysis, and spits out the result, but in a stackable manner.  Thus the title; I want to use the for loop's index to mark the array element for building a new array.
    See the image attached.  A 2D array of 9 columns (X, Y1...Y8) is analyzed such that each data set, (X, Y1), (X, Y2)...(X, Y8) is bundled, graphed, run through a B-spline Fit, of which is also graphed.  I need to replace this with something that looks like the for loop structure shown.  
    I just don't know how to get those two data bundles [(X, Yi) and it's smoothed pair] out of the for loop in a stacked set from every iteration of the for loop.
    Again the title, I think I want to build a new array where i use the index of the for loop to control the entries of the new array.  But I can't see how to do that.
    Any help would be appreciated.
    Attachments:
    NeedForLoopForThis.PNG ‏30 KB

    Hello H.R. Dunham, and welcome to the forum!
    It seems that you may be looking for Auto-Indexing, a basic feature of loops in LabVIEW.  You'll need to transpose your array before wiring it into the for loop, as elements are auto-indexed by row before column, but at that point you should be able to operate on each column and output an array of n cluster elements corresponding to your input columns.  Auto-indexing tunnels look like brackets to indicate each element will be indexed automatically- this should be the default when wiring an array into a for loop or when wiring anything out of a for loop.
    As for how to build your pairs, I suggest removing the X column and creating a "starter" cluster containing your X data and placeholder Y data before entering your "Y" processing loop.  Use the bundle by name function in the for loop to insert your processed column data into the cluster and auto-index the cluster output. Flow would be something like this:
    1) Gather data
    2) Split X and Y using standard array operations
    3) Create "template" cluster with shared X data
    4) Pass template cluster and Y-column array into an auto-indexed for loop.
    5) Insert processed Y data into cluster inside loop.
    6) Auto-index cluster data out of loop.
    This tutorial is probably also a good place to get started:
    Getting Started with NI LabVIEW Module 3: Loops
    http://www.ni.com/white-paper/7528/en/
    Hope that helps!
    Regards,
    Tom L.

  • How to find out the max/min value of one field corresponding to a second field in HANA through graphical way.

    Hi,
    I am trying to find out the latest delivery date(EINDT)  for each purchasing document (EBELN) through graphical way.
    The view contains other fields apart from the above mentioned two fields.
    When only the two fields (EBELN, EINDT) are there, then in semantics, I can select 'Max' as aggregation to get the maximum value for each document.
    If I do like this, then I need to join more than 3 views and also so many joins in calculation view. Taking so much time for data preview.
    Hence , please help me in getting the solution while the view contains other fields also.
    Thanks in advance.
    Thanks,
    Jyothirmayi

    Hi Sreehari/Vinoth,
    Thank you for your replies.
    if only two fields are then I can get the max/min values of one field corresponding to other field.
    But more than two fields are there with different values, then let me know how to find out the max/min value of a particular filed corresponding to the 2nd field with other fields also should be in the output.
    I hope you understood my issue.Please revert in case of questions.
    Thanks & Regards,
    Jyothirmayi

  • Finding max value in column using java..

    Hello there!!
    I have a problem that i tried finding in google but did not get what i wanted.. that's why i hope you guys could help me out.
    How do i find the maximum value in a column using resultset..
    for example..
    Connection con = DriverManager.getConnection("jdbc:mysql:///eproc","root", "");//eproc is dbase name in MySQL
    Statement stmt=con.createStatement();
    ResultSet rs;
    rs = stmt.executeQuery("SELECT MAX(id) FROM cat_work_sor_category");now, how do i use resultset to make sure i get the max value and assign to integer variable...
    Please do help me out.
    Thankyou.

    Connection con =
    DriverManager.getConnection("jdbc:mysql:///eproc","roo
    t", "");//eproc is dbase name in MySQL
    Statement stmt=con.createStatement();
    ResultSet rs;
    rs = stmt.executeQuery("SELECT MAX(id) FROM
    cat_work_sor_category");
    Integer MaxValue = new Integer(-1);
    if(rs.next()){
    MaxValue = rs.getInt(1);
    int MAX_VALUE = MaxValue.intValue();

Maybe you are looking for

  • Restrict the use of index while quering

    Hi All I have a simple emp table with columns empid, name, sal. Empid has a primary key imposed. Now when i write a statement like this, select * from emp where empid = <value>; the optimizer will make use of index. The question is........... is ther

  • Defining Keystrokes on a JSF Page

    Hi there and Happy Holidays. I have a question regarding keystrokes in JSF. On a conventional HTML page, a developer can use JavaScript to respond to keypress events. For example, I can have a button be clicked when a user presses F12 or Ctrl-C. I si

  • ITunes 9 using old proxy settings

    (Using iTunes 9.0.3.15 on a Win2k domain with a non-authenticating proxy server.) When you access the app store you now get a iTunes login for your proxy server and if you check the prompt to save your settings it saves that password in some undeterm

  • Lumia 900 update error 80070424

    I have just bought Nokia Lumia 900, and everything works and looks very well. But the phone won´t update its firmware (current version is the factory preset of 2175.2101.8779.12201). ZUNE update procedure keeps bombarding me with 80070424 error. Alre

  • Calculate Weeks in a period

    Hi All, How do I calculate the number of weeks in a given period. say for example startDate = 24th Nov 2002 enddate = 31st dec 2002. How can I find the weeks within this period. I tried calculating the time difference but that didn't help. Any Ideas?