array sorting

I have attached a simple VI to power a table the latest values on top.

Please if someone can suggest a better way.

Alok.p wrote:

I have attached a simple VI to power a table the latest values on top.

Please if someone can suggest a better way.

I have not uderstand why call you the output terminal iteration "non-random. feed to the range", because it is certainly not a random number as the code ensures that the current number is always greater than any number existing in the table (except in the first iteration where it is equal), the problem, as it is, a meaningless.

Suppose you have an array of 10 elements (you can also resize the table index to actually show all 10 items, currenty we see only 9) and you want to add the new value to the 0 position (independently!), change of all the other upward with each addition.

In this case, the following would be a solution that keeps track of the statically allocated table. The elements will always be sorted in historical sort order, newest on top, and the size of the array is fixed to 10 elements, retaining the 10 most recent additions.

The label of the button is also misleading, because this is a lock, that one element will be added with each press. It should be called "Add item" instead.

(To run the event structure would be better for the current code (not shown)).

Tags: NI Software

Similar Questions

  • Array.sort() compare strangeness function in ExtendScript

    I write this in InDesign Scripting forum, because I met the problem while he was working on a script for InDesign CC 2015, but it seems to cover all of ExtendScript.

    In my script, I use the method array.sort() with a custom comparison function to sort an array of objects with respect to one of their properties. I will introduce a version widespread in the party so that it is easier to analyze and reproduce.

    var myArray = [{
        name: "A",
        size: 20
    }, {
        name: "B",
        size: 10
    }, {
        name: "C",
        size: 30
    }, {
        name: "D",
        size: 30
    }];
    
    myArray.sort(
        function(a, b) {
            if (a.size > b.size) {
                return 1;
            }
            if (b.size > a.size) {
                return -1;
            }
            return 0;
        });
    
    
    var names = [];
    for (var i = 0; i <= myArray.length - 1; i++) {
        names.push(myArray[i].name)
    };
    names;
    

    The expected result is "B, A, C, D. B must go before A, as its size is smaller than A, while C and D should remain unchanged, because their size is equal.

    However, the result provided by ExtendScript is "B, A, D, C. For some reason, C and D become reversed.

    I believe that the source of this behavior lies with incorrect treatment of ExtendScript part returns 0 .

    To confirm that, I replaced the triage function with

    myArray.sort(
        function(a, b) {
            return 0;
        });
    

    which, according to my understanding of how the comparison functions are supposed to work, must return the entire unchanged table (regardless of the entry). But in this case ExtendScript treats as "B, C, D, A.

    I would be very grateful if someone could confirm if it is indeed a bug (or at least a dull implementation of the ECMAScript standard). Or is everything works as it should and the error on my part?

    Advice as workaround for this problem would also be very useful. Thank you!

    Thanks for that suggestion!

    Your answer made me read on different algorithms sort and their implementation in the different JavaScript engines. Apparently, ExtendScript uses what is called an unstable sorting algorithm, which is precisely the cause of a non desired behavior with values of the sort condition.

    To implement a different and stable algorithm (for example, merge sort) in your script is certainly an option, but it seemed overkill for my purposes.

    Fortunately, I was able to find another solution.

    First, add a property 'position' for each element of the array, based on its current position. For example:

    for (i = 0; i < myArray.length; i++) myArray[i].position = i;
    

    Then, simply change the latest state of the sort function so that it compares the position of each element:

    myArray.sort(function(a, b) {
        if (a.size > b.size) {
            return 1;
        }
        if (b.size > a.size) {
            return -1;
        }
        if (a.size == b.size) {
            return a.position - b.position;
        }
    });
    

    I hope this will be useful to those who might encounter the problem in the future.

  • Array.sort is unstable?

    Use Array.sort, when the compareFunction always retrun 0, it will change the order of the elements in array. (in javascript, is not)

    is the quick sorting using Array.sort, which is unstable?

    and how to fix it not change the order of the elements.

    Thanks for any help.

    Here's the test code:

    Student.As

    package
    {
              public class Student
              {
                        public function Student(name:String, age:int)
                        {
                                  this.name = name;
                                  this.age = age;
                        }
      
                        public var age:int;
      
                        public var name:String;
      
                        public function toString():String
                        {
                                  return "[name=" + name + " age=" + age + "]";
                        }
              }
    }
    
    

    Applicatoin.MXML

    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                                            creationComplete="application1_creationCompleteHandler(event)">
              <mx:Script>
                        <![CDATA[
                                  import mx.events.FlexEvent;
      
                                  private var ac:Array = [
                                            new Student("ST1", 21),
                                            new Student("ST2", 21),
                                            new Student("ST3", 21),
                                            new Student("ST4", 21)
                                  ];
      
                                  protected function application1_creationCompleteHandler(event:FlexEvent):void
                                  {
                                            ac.sort(function(a:Object, b:Object):int
                                            {
                                                      if (a.age > b.age)
                                                                return 1;
                                                      else if (a.age < b.age)
                                                                return -1;
                                                      return 0;
                                            });
                                            trace(ac);
                                  }
      
                        ]]>
              </mx:Script>
      
    </mx:Application>
    
    

    the result is:

    [name=ST3 age=21],[name=ST2 age=21],[name=ST1 age=21],[name=ST4 age=21]
    

    Array.sort has change the order of the elements in array

    See http://stackoverflow.com/questions/3026281/array-sort-sorting-stability-in-different-brows ers

    Array.sort is not necessary to be stable according to ECMA.  Looks like the recent browsers have implemented a stable sort, but Flash does not.

    AS3Commons claims to have a stable sort.  See http://code.google.com/p/as3-commons/source/browse/trunk/as3-commons-collections/src/main/ actionscript/org/as3commons/collections/utils/ArrayUtils.as

  • Built-in sort with Arrays.sort

    I have multidimensional array that contains a number as new arr int [10] [10] and that you want to sort according to the last column. Arrays.sort is a simple way to do it, but what happens if I don't want a real movement elements occur by Arrays.sort (arr [] []). Frankly, I'm interested in winning positions but not to grant the lines. Can I pass it arrange step because not interested in changing the original table? For the moment, I sort the table with Arrays.sort then index of table row and I fixed the position number pair. For example arr [0] has rank 1, arr [1] has the rank of 2 etc. If sorted according to the last column.

    Published by: totalnewby on May 23, 2011 22:51

    totalnewby wrote:
    I just need to know where the items would be positioned if they have been sorted. I made copy of the table at the moment and my program is successful, even if it takes a lot of time and additional memory to perform the copy because this table has billions lines in reality. If you can suggest less time-consuming solution do let me know.

    This is my standard example of how to do this sort of indirect.

     public static void main(String[] args) throws Exception
        {
            final Words words = new Words("/usr/share/dict/words");
            final List data = new ArrayList();
            for (int i = 0; i < 10000; i++)
            {
                String[] row = new String[10];
                for (int j = 0; j < row.length; j++)
                {
                    row[j] = words.getRandomWord();
                }
                data.add(row);
            }
    
            final Integer[] indirectIndex = new Integer[data.size()];
            for (int i = 0; i < indirectIndex.length; i++)
            {
                indirectIndex[i] = i;
            }
    
            final Comparator indexComparator = new Comparator()
            {
                @Override
                public int compare(Integer left, Integer right)
                {
                    int result = 0;
                    for (int i = 0; result == 0 && i < data.get(left).length; i++)
                    {
                        result = data.get(left).compareTo(data.get(right)[i]);}return result;}};
    
    Arrays.sort(indirectIndex, indexComparator);
    
    for (int i = 0; i < 100; i++){System.out.println(indirectIndex[i] + "\t" + Arrays.toString(data.get(indirectIndex[i])));}}
    
    You just need to create a Comparator for sorting the index array that uses the last entry in each row of real data array when comparing a row rather than all the row entries as I have done. 
    
  • Arrays.sort

    Why did the Arrays.sort method defined as

    public static sort (Object [] a) Sub

    Instead of

    public static sorting Sub (comparable [] a)?

    user9987428 wrote:

    jverd wrote:
    In this way we can sort an array whose elements are all mutually comparable, even if the table itself is not declared as being of a Comparable type. I can't think of a specific use case where it would be useful, but that's the only reason why I can think for deliberately to make that decision.

    Dear jverd, I'm not sure that the case you are referring. I tried the following code and it gives a runtime Exception.

    The current implementation does not allow it and even though I was thinking exactly the same thing as jverd suggested, I think it is more likely that it's just an oversight.

  • Unexpected result with Array.sort

    There seems to be a problem with the sort function when sorting the table contains several elements that are equal. I tried to illustrate this in the most simple form below:

    var test1:Array = ['a', 'b', 'this,' would be '];

    var test2:Array = [', 'c', 'b', 'a'];

    var test3:Array = ['a', 'b', 'c', ' a'];

    var test4:Array = ['a', ' a ',' b ', 'a'];

    trace (test1.sort (Array.RETURNINDEXEDARRAY)); Should be 0,1,2,3 (well!)

    trace (test2.sort (Array.RETURNINDEXEDARRAY)); Should be 3,2,1,0 (good!)

    trace (test3.sort (Array.RETURNINDEXEDARRAY)); Must be 0,2,3,1 (evil)

    trace (test4.sort (Array.RETURNINDEXEDARRAY)); Must be 0,1,3,2 (evil)

    / * Output

    0,1,2,3

    3,2,1,0

    3,0,1,2

    3,1,0,2

    */

    Can anyone find a reason of incompatibility, or is this a bug in the sorting method?

    test3: must be 0,3,1,2 or 3,0,1,2.  They are the same.

    test4: 0,1,3,2 is the same as 3,1,0,2 is the same as 1,0,3,2 is the same as 0,3,1,2 etc.  That is to say, as long as the index 2 is the last, they still.

    Oh, I see the problem.  you think flash is assign an index to the elements of the original array.

    It is not the case.  the method released the list of indices in the sort order.  IE, 0,3,1,2 means the original elements of 0th and 3rd tables are first and 2nd and the 1st element is the third and the 2nd element is the last.

    so, if you wanted to list the elements of original paintings using your sort order for test3, for example, you would use:

    test3 [0], test3 [3], test3 [1], test3 [2] and you expect, a, b, c

  • How to create dynamically sorting table?

    For example, I have a table with 2 columns: 'Name', 'value x; and 1 table with columns 'name' value 'y' (which is based on the value of x + a formula). What I want to achieve is to get table2 sorted whenever I change value in table1. The "Filter/Sort" tool only applies sort once and doesn't react to any changes made to the table 1.

    I don't know how the practice is (I find it easier at the station just manually), but here's a way to generate an array sorted automatically.

    Add a column "index" for the value of Y in the same table (this can be hidden if you want) with a formula like this:

    The formula in C2, filled to the bottom:

    = B2 + 5 + LINE () / 10000

    The idea is to calculate Y using some formula that you use and then add a very small number based on the number of line so that it becomes a unique value that can be used for searches, even when the same value 'original' appears more than once.

    Then in column B of the table "Sorted" list the values for Y in Crescent order like this:

    The formula in B2, filled to the bottom:

    = SMALL (Table 1: $C, ROW (−1))

    And, finally, to get the name corresponding to this value of Y as this:

    The formula in A2, filled to the bottom:

    = INDEX (table 1: $A, MATCH (B2, table 1: $C, 0))

    Now, whenever you change a value in the column X, "Sorted" table is automatically sorts.

    SG

  • request (?) featured: matrices or tables for a particular column sort

    Hello all-

    This may be a stupid question, because I'm always still not quite clear on what are the differences between the matrixes and 2D arrays in LabView. So far the only distinction I seemed to find, it is that certain features of table return errors when the matrices are entered and vice versa.

    Anyway, here's my question.

    Suppose I have a matrix where the first column represents the 'values' that have been measured and the second column 'account'. I would like to take a unordered matrix (i.e., the value column is not ordered) and recover a matrix that has had its lines re-arranged according to the values in the first column.

    For example, if my matrix:

    [5-1;

    0 11;

    1-5;

    3-10]

    I would like to as labview to return:

    [0-11;

    1-5;

    3-10;

    1 of 5]

    When I was trying to find a way to do it (without writing my own sorting routine which, admittedly, wouldn't be too bad, but I'm a lazy programmer ), the only thing I found that came close was the 'matrix of D 1 sort' Subvi. However, even if I had to store the values in a table and charges in another table, I'd be able to do is sort the table values. I wouldn't be able to tell what labview reorganization, I would need in order to perform the same reorganization charges.

    I'm a little surprised that there isn't a quick and intuitive way to do this (at least that I can find). A LabView feature addition that could help with this problem would be if the "1 D Array sort" routine returned a second output - a vector with the mapping of the index used - similar to MATLAB. MATLAB help for the function 'out ':

    "[There, I] = SORT(X,DIM,MODE) also returns a matrix of index I.. «If X is a vector, then Y = x.»

    Of course, there may be a quick fix for what I'm missing...

    Take a look at this post. I don't know that you can change for your particular type of data.

    (in contrast to the first colum, create the sort key, table 2D reconstructed according to key)

  • User-defined sorting matrix

    Anyone know how I can better sort an array of a user-defined class? I need to sort by an int of this property.  Also, I need to keep this table permanently if that makes a difference...

    Want to watch Arrays.sort and comparator class. Standard Java.

  • How to sort a table double in blackberry?

    I need to sort a double table containg frequencies. I have java we can do by the method "Arrays.sort (). But Blackberry does not support table double sorting with this method. Someone has any idea how to do? Thank you.

    implement your own sorting algorithm must be covered by each course programming first half, I'm sure you can find many of them online.
    If this sounds too awkward, you could use instead of double [] objects and set up your own comparison.

  • HOW to: Sort table of VC:HostSystems by name

    Hello

    First of all, I'm new to Javascript.

    I have the following javascript code, and I want to sort my table of parameter Listehotes by host name.

    I tried the array.sort(); function, but as it is not a list of host names and objects. The result is done by host name.

    Does anyone know how to get the desired result?

    / Brian

    --------------------------------------

    var allHosts = VcPlugin.getAllHostSystems ();

    HostNameToMatch = 'ESXi ';

    var host = new Array();

    for (var i in allHosts) {}

    If (allHosts [i].name.match (new RegExp (HostNameToMatch, 'i'))) {}

    hosts.push (allHosts [i]);

    }

    }

    Parameter Listehotes = host;

    HostList.sort ();

    --------------------------------------

    Hi Brian,.

    use function to extend kind...

    example to the low made by the brain dump, then look in the API in table Explorer, there is also an example

    Kind regards

    Andreas

    var allHosts = VcPlugin.getAllHostSystems ();

    HostNameToMatch = 'ESXi ';

    var host = new Array();

    for (var i in allHosts) {}

    If (allHosts [i].name.match (new RegExp (HostNameToMatch, 'i'))) {}

    hosts.push (allHosts [i]);

    }

    }

    Parameter Listehotes = host;

    HostList.sort (byName);

    byName (a, b) function

    {
         return (a.name <>
    }
  • Table is obtained from static method Enum "values()" intended as sorting?

    Hi all

    My question is on the table that you get when you call the static method "values()' from the enumeration.

    Is it intended that the default sort? And especially: can I use Arrays.binarySearch () with?

    Thank you.

    Adriano

    The values are returned in the order in which they appear in the definition of the enum. So no, not guaranteed sorted unless you maintain with obstinacy sorted State yourself. A call to Arrays.sort () can fix it, of course.

  • How can I sort VcHostSystem

    Hello

    I am new to both Orchestrator and javascript.  I'm trying to create a script to automate the virtual construction in my environment.

    I have a little trouble with the sorting.

    I can't find how to sort VcHostSystem.datastore.summary.freeSpace

    I would like to be able to select the number of logical unit with more free space.  It's really easy to PowerCLI, but I can't get by in Orchestrator.

    We know?

    Hi Aureus,

    Here is a very small example of use in an action or a workflow.

    • Entry: ArrDS [(Array/Datastore)]
    • Output: [Datastore] DS

    DS is set in the store of data in ArrDS with more free space. There is no error and management regardless of the type of data store (local / shared).

    function sortDS (a, b)
    {
     return (a.summary.freeSpace < b.summary.freeSpace);
    }
    ArrDS.sort(sortDS);
    DS = ArrDS[0];
    

    If you look in the browser in vCO API Array-> sort, you will find a very brief explanation of the implementation of the sort.

    If you use spell no function, like sort(), members of the group are sorted by primary type. In the case of scalar (number, String,...) it works perfectly. But on complex types as data store that you want to sort on a special criterion and is therefore define an own sorting function.

    Hope it will be comfortable.

    Kind regards, Andreas

  • Need to sort out my paragraphStyleGroup

    Hi all

    See my script which does not sort below paragraph style. But I need to sort my paragraph styles as well as my group of paragraph style styles.

    Here's the code to sort the paragraph styles:

    myParStyles_Sort (app.activeDocument);
    function myParStyles_Sort (doc)
    {
    var string_array = sort_par_names (doc);
    for (var i = 0; i < string_array.length; i ++)
    () doc.paragraphStyles.item ([i] string_array) .move
    LocationOptions.after, doc.paragraphStyles [i + 2])
    }

    function sort_par_names (doc)
    {
    var table = doc.paragraphStyles.everyItem () .name;
    Array.Shift (); Array.Shift ();
    array.sort return (myCaseInsensitive);
    }
    function myCaseInsensitive (a, b)
    {
    return a.toLowerCase () > b.toLowerCase)
    }

    Some current examples of style sheets

    Picture 13.png

    Need to change this format as indesign made with sort by name option.

    Picture 14.png

    Thanks in advance for your time and support.

    Chang

    You can use a recursion, like this:

    myParStyles_Sort (app.activeDocument);
    function myParStyles_Sort (doc){
        var myItem;
        var myLastItem;
        var string_array = sort_par_names (doc);
        for (var i = 0; i < string_array.length; i++){
            myItem = doc.paragraphStyles.item (string_array[i]);
            if (myItem.hasOwnProperty("paragraphStyles")){
                myParStyles_Sort(myItem);
            }
            if (i == 0){
                myItem.move (LocationOptions.AT_BEGINNING);
            } else {
                myItem.move (LocationOptions.AFTER, myLastItem);
            }
            myLastItem = myItem;
        }
    }
    
    function sort_par_names (doc){
        var firstIndex = doc instanceof Document? 2: 0;
        var myArray = doc.paragraphStyles.everyItem().name.slice(firstIndex);
        myArray = myArray.concat(doc.paragraphStyleGroups.everyItem().name);
        return myArray.sort ();
    }
    
  • Sort by name via the script

    Hello world

    I would be grateful if someone could give some clues to sort by name from the

    Paragraph Styles, character Styles, Styles of object and panels color chart

    via the script.

    Thank you in advance.

    Edson Furman

    [email protected]

    To sort the styles I used the script below - works in CS3 and CS4 if it has been awhile since I finally tried. It could be coded with more elegance, but it worked well as it is. He does not account groups of style: I don't know what happens if your documents contain a sort you would better try.

    As for shades, these are not so easy to sort. There was a discussion about this at one of these sites:

    http://www.Hilfdirselbst.ch/gforum/gforum.cgi?jump=Forum%3d4

    http://InDesign-FAQ.de/

    Peter

    #target indesign
    
    sort_par_styles (app.documents[0]);
    sort_char_styles (app.documents[0]);
    sort_obj_styles (app.documents[0]);
    
    //-------------------------------------------------------------------------------
    
    function sort_par_styles (doc)
        {
        var string_array = sort_par_names (doc);
        for (var i = 0; i < string_array.length; i++)
            doc.paragraphStyles.item (string_array[i]).move (
                LocationOptions.after, doc.paragraphStyles[i+2])
        }
    
    function sort_par_names (doc)
      {
      var array = doc.paragraphStyles.everyItem().name;
      array.shift (); array.shift ();  // exclude [No p.] and [Basic p/]
      return array.sort (case_insensitive);
      }
    
    //-------------------------------------------------------------------------------
    
    function sort_char_styles (doc)
        {
        var string_array = sort_char_names (doc);
        for (var i = 0; i < string_array.length; i++)
            doc.characterStyles.item (string_array[i]).move (
                LocationOptions.after, doc.characterStyles[i+1])
        }
    
    function sort_char_names (doc)
      {
      var array = doc.characterStyles.everyItem().name;
      array.shift ();  // exclude [None]
      return array.sort (case_insensitive);
      }
    
    //-------------------------------------------------------------------------------
    
    function sort_obj_styles (doc)
        {
        var string_array = sort_obj_names (doc);
        for (var i = 0; i < string_array.length; i++)
            doc.objectStyles.item (string_array[i]).move (
                LocationOptions.after, doc.objectStyles[i+4])
        }
    
    function sort_obj_names (doc)
      {
      var array = doc.objectStyles.everyItem().name;
      array.shift (); array.shift (); array.shift ();  array.shift (); // exclude  [None], [Basic Graphics Frame], [Basic Text Frame], [Basic Grid]
      return array.sort (case_insensitive);
      }
    
    //-------------------------------------------------------------------------------
    
    function case_insensitive (a, b)
      {
      return a.toLowerCase() > b.toLowerCase()
      }
    

Maybe you are looking for

  • Satellite L350-171 - network printer installation

    I have problems to install my Canon Pixma IP4300 printer as a network printer. The printer is connected to a desktop PC, then a router, Dynamode R-ADSL-C4-2. This is connected to the laptop by a cable that was previously connected to my old laptop. H

  • A keyboard of shot is available for 8 Stream?

    I have a Stream8 tablet. Is there an interface of keyboard style by sweeping as the one I have on my Android phone?

  • Name on the track of graph

    Hello Is there anyway that I can control the names on a graph plotted in the graph XY? My goal is to have a name that follows the chart according to which graphic I choose Etc when I choose Chart 1, a name appears point plotted on the graph, the same

  • Engine does not turn

    That is the problem. I have connected to Umi-7764 and a scientific P70360 drive of the Pacific, the wiring is as follows: UMI-7764-> p70360 J4 terminal screw control IO 26 female pin inhin1 (bar above)-> fault-(PIN 8) inhout1 (top bar)-> enable-(6-pi

  • slui.exe is not compatible with this version of windows.

    I installed an iso image of windows 7 Professional and haven't configured my backup when I deleted slui.exe thinking it was a virus. It is not in my trash. I copied the system32 file from active computer windows 7 Professional, which included slui in