Select X# of variables from array at the furthest possible intervals.

Ok, I've been working on this one for a while and I'm thinking I'm either missing something really stupidly simply because of it, or I've got my equation wrong still. 
Basically, what I'm trying to do is select X number of items out of an array.  The only catch is, these items need to be as far apart from each other as possible.  So for example, one time I might have an array with 93 items in it which I need to grab 36 of them, evenly spaced through the array (so the first one would be the first one in the array, and the last one would be the last in the array.
How would I go about telling the script to grab the correct array values (the most evenly spaced ones), ending up with only the X amount of output values?
Thanks!
dgolberg

Hmm, this is kind of a different perspective than what I was originally thinking, but it might work.  I'll have to test it out, though it would require me running the array twice; the first time picking out the specific ones and splicing them out of the array, the second simply grabbing the remainder.
To put it a little differently, what I was originally thinking is cycling through an array (this array's length and content varries depending on the input), and would grab the the "masters" out of the array at the set intervals (these intervals are where I'm having the most trouble), and anything it finds matching a set range for the current loop cycle that isn't considered a "master" is placed under the master as a "slave" (or essentially, a duplicate).  Below is an example of one of the loops I'm using (I have 3 nested loops in order to cycle through 3 "dimensions" of values) with my last attempt at this issue (which is only correct in certain ranges rather than all ranges like I need).
var DF = tA.length / mNum;  //tA.length is the array length, mNum is the number of masters desired from that array.  For example, array length of 100, mNum of 75; DF = 1.333333....
var master = 0;
for(var z=range[1];z<range[2]+2;z=z+5) { //Cycles through the array 5 units at a time (to speed up the script)... There are 2 other loops above this using the y and z variables seen in the if statements below.
     for(var i=0;i<tA.length;i++) { //Cycles through the tempArray to find matches to the current cycle of the above loops, +/- 2
           if(tA[i][0] <= x + 2 && tA[i][0] >= x - 2 && tA[i][1] <= y + 2 && tA[i][1] >= y - 2 &&tA[i][2] <= z + 2 && tA[i][2] >= z - 2 && master < 1) { //Checks for a match, and if the master is less than 1, it sets the match as a master.
               master = master + DF; //Adds the DF (short for Dupe Frequency) to the current master number.
               outArray.push(tA[i]); //Set the match as a master
          } else if(tA[i][0] <= x + 2 && tA[i][0] >= x - 2 && tA[i][1] <= y + 2 && tA[i][1] >= y - 2 &&tA[i][2] <= z + 2 && tA[i][2] >= z - 2 && master >= 1) { //Checks for a match, and if the master is greater than 1, it sets a duplicate.
               master = master - 1;
               outArray[outArray.length-1].push(tA[i][3]); //Set the match's name as a slave under the last master
Basically, using the code above; I need it to somehow (while cycling through the tA.length loop), figure out how often it should grab either a slave or a master (depending on which there are more of), and then the next X number of matches are either a master or a slave (again, depending on which there are more of).  So, for example, if there are 25 masters, out of 100 total items in the array, it would pick one master, the next 3 matches would be slaves, and then it would pick another master, 3 more slaves, etc. etc.  Where things start getting out of whack is when the intervals start ending up in fractions (say every 1.5 is a slave).  Obviously, you can't grab half of one, so you'd need to do a pattern more like: 1 master, 1 slave, 1 master, 2 slaves, 1 master, 1 slave; etc.
The part I'm having trouble with is getting a working equation that knows how often to pick the (in the example above) slaves based on this varying pattern, and do so accurately regardless of the array length to master/slave ratio (the above method seems to get further off as the mNum gets closer to the tA.length).
I guess, more than anything really, I'm just having trouble getting the math to work out right as I'm apparently using the wrong equation in my code.  If anyone has any ideas though, let me know.

Similar Messages

  • Is it possible to pass variables from Tidal to the Peoplesoft run controls?

    Does anyoen know
    •1) Is it possible to pass variables from Tidal to the Peoplesoft run control page such as current date?
    An example would be updating run control parameters for a PSQUERY.
    •a) From date
    •b) To date
    •c) Business units
    Thanks,
    Jay

    Edit the job - go to Run Controls Parameters tab - select the param you want in the Override column then click on the Variables button on the bottom and select the variable you want

  • What is the furthest possible date on the iphone calendar?

    What is the furthest possible date on the iphone calendar?

    pdroth wrote:
    Your phone will be long dead before then.
    But will I still be able to get an out-of-warranty option for $269 for my iPhone 5S?

  • Passing a variable from subreport to the main report

    Hi guys, was unable to google this, so Im urning to you guys:
    I was wondering whether it was possible to do this:
    I have a subreport taking data from a table. In the main report, in the suppres condition of details section containing this subreport, I need to have a variable containing the total count of rows in that table. I know there are shared variables for that, but the problem is, that the variable in the condition is processed sooner than the one in the subreport.
    Any ideas on this?
    Thanks a lot

    To Sharma:
    Hi, unfortunately I can't. The subreport has its specific position in constallation with previous and following sections and must be right there.
    To Raghavendra:
    Hi, that was my first idea, but the problem is as I explained in my first message.
    To both:
    I have a table in subreport. This subreport is in main report positioned in details section "x". and I want to use that shared variable in the suppress condition of section "x". The problem is that the formula in suppress condition is processed sooner than the formula assigning a value to the shared numbervar inside the subreport.
    and thats what im looking for - a workaround for that. btw im using CR 8.5
    thanks again guys

  • Reset a variable from flash in the parent php page

    I know how to pass vars from php to flash and from flash to a
    "new" php page but here is my question.
    I have a php page (page1.php) with some HTML and a php
    variable called $number. page1.php also has an embedded test.swf
    movie. While working with the test.swf movie, I want to send data
    back to the $number var on the page1.php without reloading the
    page1.php because then it would reload the test.swf movie.
    I have been able to use javascript to change background
    colors on page1.php from within the test.swf movie but cannot
    figure out how to set a php variable from within the test.swf
    movie.
    Is this possible?

    That's what I ended up doing.
    I wrote the var to a db from page1.php using a separate php
    page and then changed the data in the db from flash using the same
    separate php page.
    Doing this made the same var or data available to both
    page1.php and test.swf without changing state.
    Just wanted to know if there were another way without using a
    db or xml file.

  • Text variable for 0calmonth in the rows possible ?

    Hello BW Experts,
    I have 0calmonth in the rows and restricted key figures in the column. Wondering if we can show the month description in the rows using text variable?
    Please let me know if that is possible and what are the steps.?
    Suggestions appreciated.
    Regards,
    BWer

    Hi,
    Using Text variables you can display the headings in the reports.
    Thanks
    Reddy.

  • Output count of SELECT statement is diff from count(*) of the same query

    Has this ever happened to you?
    I was wondering why some of the items were not appearing in my output. I have this select query:
        SELECT
            bukrs
            gjahr
            hkont
            belnr
            wrbtr
            dmbtr
            matnr
            bschl
            kunnr
            vbeln
            shkzg
        FROM bseg
        INTO CORRESPONDING FIELDS OF TABLE i_output
        FOR ALL ENTRIES IN i_bkpf
        WHERE
            bukrs EQ i_bkpf-bukrs
            AND belnr EQ i_bkpf-belnr
            AND gjahr EQ i_bkpf-gjahr
            AND hkont IN hkont
            AND hkont IN
                ('0004000000',
                '0004000010',
                '0004000020',
                '0004000030',
                '0004000040')
    When I tried to put sample filters (bukrs: 1000; belnr 1800000016; gjahr: 2005; hkont: 4000000), I am getting 3 entries from bseg. But when I tried using SE16 or SE16N, I am getting 6 (which is the expected output). When I modify the same SELECT query to return just the output count, I AM getting 6.
        SELECT count(*)
        FROM bseg
        INTO count
        FOR ALL ENTRIES IN i_bkpf
        WHERE
            bukrs EQ i_bkpf-bukrs
            AND belnr EQ i_bkpf-belnr
            AND gjahr EQ i_bkpf-gjahr
            AND hkont IN hkont
            AND hkont IN
                ('0004000000',
                '0004000010',
                '0004000020',
                '0004000030',
                '0004000040')
    Do you have any idea why this happens? My internal table is a standard table with no header line and no OCCURS statement.
    Kyle

    Hello Kyle,
    Thats because when using FOR ALL ENTRIES, it will delete the duplicates if the records selected dont have all the primary keys specified in the select query. In your first select query, the field BUZEI is missing which makes the records unique. Change your first select query as this and try
    SELECT
            bukrs
            gjahr
            hkont
            belnr
            buzei   -------> Add this and check
            wrbtr
            dmbtr
            matnr
            bschl
            kunnr
            vbeln
            shkzg
        FROM bseg
        INTO CORRESPONDING FIELDS OF TABLE i_output
        FOR ALL ENTRIES IN i_bkpf
        WHERE
            bukrs EQ i_bkpf-bukrs
            AND belnr EQ i_bkpf-belnr
            AND gjahr EQ i_bkpf-gjahr
            AND hkont IN hkont
            AND hkont IN
                ('0004000000',
                '0004000010',
                '0004000020',
                '0004000030',
                '0004000040')
    Vikranth

  • How to select hightest 10 values from array?

    Hi there,
    say i got an array of double, how do i find the top ten highest values in the array?
    Thanks
    Arlef

    class Foo {
        public static void main(String[] args)  {
            new Foo().go();
        void go()
            Random rand = new Random();
            double[] d = new double[50];
            for (int i = 0; i < d.length; i++)
                d[i] = rand.nextDouble() * 25;
            double[] highest = getHighestValues(d, 10); // get ten highest
            printArray(d, System.out);
            System.out.println();
            printArray(highest, System.out);
        double[] getHighestValues(double[] array, int numberOfElements)
            if (numberOfElements > array.length) throw new IllegalArgumentException("not enough elements");
            double[] d = new double[array.length];
            System.arraycopy(array, 0, d, 0, array.length);
            Arrays.sort(d);
            double[] result = new double[numberOfElements];
            System.arraycopy(d, d.length - (numberOfElements), result, 0, numberOfElements);
            return result;
        void printArray(double[] d, PrintStream out)
            out.print("[");
            for (int i = 0; i < d.length; i++)
                if (i > 0) out.print(", ");
                out.print(d);
    out.print("]");

  • How do I get sdo_point into C host variables from OTT structures?

    How do I get sdo_point info into C host variables from structures generated by OTT?
    Databse Version 10.1.0
    I am using OTT to generate C structures for the Oracle Spatial datatype sdo_geometry. The file is generated as
    #ifndef GEOMETRY_ORACLE
    # define GEOMETRY_ORACLE
    #ifndef OCI_ORACLE
    # include <oci.h>
    #endif
    typedef OCIRef sdo_geometry_ref;
    typedef OCIRef sdo_point_type_ref;
    typedef OCIArray sdo_elem_info_array;
    typedef OCIArray sdo_ordinate_array;
    struct sdo_point_type
    OCINumber x;
    OCINumber y;
    OCINumber z;
    typedef struct sdo_point_type sdo_point_type;
    struct sdo_point_type_ind
    OCIInd _atomic;
    OCIInd x;
    OCIInd y;
    OCIInd z;
    typedef struct sdo_point_type_ind sdo_point_type_ind;
    struct sdo_geometry
    OCINumber sdo_gtype;
    OCINumber sdo_srid;
    struct sdo_point_type sdo_point;
    sdo_elem_info_array * sdo_elem_info;
    sdo_ordinate_array * sdo_ordinates;
    typedef struct sdo_geometry sdo_geometry;
    struct sdo_geometry_ind
    OCIInd _atomic;
    OCIInd sdo_gtype;
    OCIInd sdo_srid;
    struct sdo_point_type_ind sdo_point;
    OCIInd sdo_elem_info;
    OCIInd sdo_ordinates;
    typedef struct sdo_geometry_ind sdo_geometry_ind;
    #endif
    I can successfully access the sdo_gtype and sdo_ordinates using the following ProC code
    exec sql begin declare section;
    int sptype;
    double coord[100000];
    sdo_geometry *spgeom;
    sdo_ordinate_array *spcoords;
    exec sql end declare section;
    /* allocate memory for the geometry host variable */
    exec sql allocate :spgeom;
    select bounds into :spgeom from boundary;
    /* retrieve the geometry type from the geometry host variable into a host variable */
    exec sql object get sdo_gtype from :spgeom into :sptype;
    /* allocate memory for the sdo_ordinate_array host variable */
    exec sql allocate :spcoords;
    /* move the coordinates from the geometry host variable into the sdo_ordinate_array host variable */
    exec sql object get sdo_ordinates from :spgeom into :spcoords;
    /* determine the number of coordinates */
    exec sql collection describe :spcoords get size into :numord;
    /* move the coordinates from the sdo_ordinate_array host variable into a host array */
    exec sql for :numord collection get :spcoords into :coord;
    I cannot, however, figure out how to get point data out of the host variable spgeom. If I prepare code analagous to the other types in the geometry structure, I get an error. I can see that sdo_point is different because it is a struct within the geometry definiton of typedef OCIRef but my knowledge of C is sufficeintly weak that I cannot figure out how to get sdo_point into C host variables. Some sample code for getting the sdo_point data would be greatly appeciated.
    Thanks, Chris

    To get point data from geometry column use following
    select a.location.sdo_point.x, a.geometrycolumn.sdo_point.y
    from tablename a;
    Do not forget to alias the table.

  • Empty query result into variable? what's the result

    It's Null Value or What?
    i write a query like this.
    select name into variable from table where pk is null;
    /*this query return nothing*/
    /*Variable = Null or variable is empty ?*/

    Generally, the contents of the variable do not change if a SELECT..INTO.. returns no rows.
    It is safer to have your NO_DATA_FOUND exception handler set the variable to an appropriate value (eg null).

  • Pls help : How To select fields and data from user_table for each tablename

    Please help with the query to generate a output which selects the code,meaning,inuse for each table in the user_table that has "CODED" as a part of table name.
    User table has some 800 table that contains CODED in the tablename.
    Desc of the table:
    DESCPTION:
    Name Null? Type
    SHORT_NAME NOT NULL VARCHAR2(20)
    CODE NOT NULL VARCHAR2(4)
    MEANING NOT NULL VARCHAR2(240)
    IN_USE VARCHAR2(1)
    NOTES VARCHAR2(2000
    UNITS NOT NULL VARCHAR2(1)
    AMOUNT NOT NULL VARCHAR2(3)
    CONVERTED VARCHAR2(1)
    RUN_NAME VARCHAR2(30)
    But all the table have code, meaning,in_use fields.
    O/P format :
    TABLE_NAME CODE MEANING IN_USE
    Help me pls.

    Not 100% sure what you want. If you want to see all the tables that have all three of those columns, then you could do something like:
    SELECT table_name, 'CODE', 'MEANING', 'IN_USE'
    FROM user_tab_columns
    WHERE column_name = 'CODE' and
          table_name like '%CODED%'
    INTERSECT
    SELECT table_name, 'CODE', 'MEANING', 'IN_USE'
    FROM user_tab_columns
    WHERE column_name = 'MEANING' and
          table_name like '%CODED%'
    INTERSECT
    SELECT table_name, 'CODE', 'MEANING', 'IN_USE'
    FROM user_tab_columns
    WHERE column_name = 'INUSE' and
          table_name like '%CODED%'If you want to select those three columns from each of the tables, then you could do something like this.
    Create a command file called, for example, makesel.sql that looks like:
    SET PAGES 0 lines 500 trimspool on feedback off;
    spool sel.sql;
    prompt spool selout.txt;
    SELECT 'SELECT '''||table_name||''', code, meaning, in_use FROM '||
           table_name||';'
    FROM (SELECT table_name
          FROM user_tab_columns
          WHERE column_name = 'CODE' and
                table_name like '%CODED%'
          INTERSECT
          SELECT table_name
          FROM user_tab_columns
          WHERE column_name = 'MEANING' and
                table_name like '%CODED%'
          INTERSECT
          SELECT table_name
          FROM user_tab_columns
          WHERE column_name = 'INUSE' and
                table_name like '%CODED%')
    prompt 'spool off;'
    spool off;
    @sel.sqlAt the sqlplus prompt run the file using @makesel.sql. This will create another file called sel.sql containing the commands to select those three columns from each table that has all three columns, then after the new file is created, it runs the file (@sel.sql). The output will be spooled to a file called selout.txt.
    HTH
    John

  • Is it possible to pass a variable from one animation to another?

    I have multiple animations on the same page. I need to pass a variable from one to the other.
    Animation One has this:
    sym.setVariable("myVarOne", 1);
    Animation Two has this:
    var myVarOneInTwo=Edge.getComposition("EDGE-12345678").getVariable("myVarOne");
    Seems like it should work, but kinda hard to tell. I put in:
    console.log("myVarOneInTwo = " + myVarOneInTwo);
    But I get: Javascript error in event handler! Event Type = timeline
    So it seems that it doesn't like getting a variable from another animation.
    Is there a way to pull a variable from one animation into another?

    Sorry also had to fix this:
    var myVarOneInTwo=Edge.getComposition("EDGE-12345678").getVariable("myVar One");
    To this:
    var myVarOneInTwo=Edge.getComposition("EDGE-12345678").getStage().getVariable("myVar One");

  • How to pass a form variable from page to page

    I have a series of 4 forms on 4 pages that update a database.
    A variable from one of the forms (doesn't matter which one, if it's
    easier one way over another, let's go that way) is passed to the
    last page, where a PayPal button will appear based on the value of
    the form variable. I am using ASP javascript and an Access
    database.
    Thanks.

    jennivazquez wrote:
    > I have a series of 4 forms on 4 pages that update a
    database. A variable from
    > one of the forms (doesn't matter which one, if it's
    easier one way over
    > another, let's go that way) is passed to the last page,
    where a PayPal button
    > will appear based on the value of the form variable. I
    am using ASP javascript
    > and an Access database.
    Either store the variable in a hidden field in the
    intermediate forms,
    or use a session variable.
    David Powers, Adobe Community Expert
    Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
    Author, "PHP Solutions" (friends of ED)
    http://foundationphp.com/

  • SELECT SYS_CONTEXT ('userenv', 'ip_address') FROM dual;

    I am using the following query
    SELECT SYS_CONTEXT ('userenv', 'ip_address') FROM DUAL:
    and the retuned row is blank.
    Any Idea why?

    SELECT SYS_CONTEXT ('userenv', 'ip_address') FROM dual
    will return the IP address of the client of the current session. If the current session is connected to a local database (i.e. not using SQL*NET), then this query appears to return NULL.
    SELECT SYS_CONTEXT ('userenv', 'host') FROM dual
    will return the host name from which the client is connected, even if the client is connected locally.
    If the host name is not sufficient, then I'm not sure what your other options are (perhaps writing a java stored procedure which returns the IP address of the database server? always connecting via SQL*Net?)

  • Passing variables from Captivate to HTML

    Hi All:
    I am trying to figure out how to export system and user variables from Captivate to the html wrapper. What I need to accomplish here is very simple. I want to capture a quizz score and pass that number back to the html file. Can anyone out there help me with this?
    I have been adding the following javascript code to my html file after publishing for testing:
         <script type="text/javascript">
         function SimpleTest()
                alert('I can call javascript');
         function ComplexTest(grade)
                alert('The grade you passed was: ' + grade);
         function ComplexAlternateTest()
                alert('The grade you passed was: ' + GradeVar);
         </script>
    I have successfully tested the first function SimpleTest() so I know that Captivate can communicate with the html file. However, I have not been able to successfully pass any system or user variables to either of the other two test functions. I suspect that I am not getting the syntax correct in the javascript call in Captivate.
    My approach has been to use execute javascript in the on slide exit. I have also tried creating an advanced action that stores a system variable to a user defined variable and then tried sending the user define variable with no success. In the javascript popup window I have been putting ComplexTest(variablename); . I don't know if this is the correct syntax or not??  I have tried using the cpQuizInfoPointsscored system varialbe with and without the $$ signs and I have tried using {score} on the quiz results page. So far no luck. I always get a "variable not defined" error message.
    Sorry for the lengthy message but you would think that something this simple would be more straight forward, but apparently it is not. Thanks in advance for your help.
    Vernon . . .

    Hi Vernon,
    I'm not a JavaScript ninja so I can't answer your question. However take a look at Philips site here http://pipwerks.com/
    He has a lot of interesting stuff in regards to Captivate and JavaScript integration so hopefully you can find the answer on his site.
    /Michael
    Visit my Captivate blog with tips & tricks, tutorials and Widgets.

Maybe you are looking for

  • ITunes on multiple Macs, sharing same library via network

    I have 2 Minis, each in a different part of the house. All music is stored on one drive and the library is shared. Is there a way to start playing music from one Mac's iTunes (say downstairs) and have the other Mac's iTunes recognize that music is pl

  • Error in posting debit balances to expense accounts

    When trying to post debit balances to expense accounts for a particular fiscal year, we are getting a short dump. Credit balances are being posted without a problem. Debit balances for other classes of accounts are posting without a problem for that

  • Starting an application using command line arguements

    Hi All, I need to launch an application by passing command line arguements. How to go about it? Thanks Sakthi

  • Text window that will scroll

    How do you get a text box that you can scroll down inside a table .......I have more info than space to put it in so i need to be able to scroll down to read it. Thanks Mike

  • Weblogic.security.ldaprealmv2.LDAPRealm problem..

    Hi All, I'm running WLS6.1sp1 and I have a bit of a snag. I've been able to successfully configure WLS6.1 to authenticate against a single development LDAP server, but I'm running into problems with my production LDAP environment. My production LDAP