Sort array with equal elements

Hi, I'm a new one.
I have a problem to sort 2d array with equal elements (it has 5000000 of elements from 1-255) for example:
1 2 1 1 3 4 5 5 6 1 2 3 (value from 1-255)
2 2 1 1 3 3 3 3 4 4 4 1 (value from 1-255)
And I need make array or matrix 255 rows vs 255 colomns, and count how many equal elements for example:
  1  2 3 4 5 6
1 0 1 0 1 0 0
2 0 1 0 1 0 0
3 1 0 1 0 0 0 
4 0 0 1 0 0 0
5 0 0 2 0 0 0
6 0 0 0 1 0 0
I'll be happy if someone could help me

I understand that it's very complicated explain.
I build 2d array from two 1darray each of them has values 1-255. So right now i must constract array or matrix 255x255 where must calculat how many times value from (1-255) for one array in another array and write this sum for each value 1-255. I try to show it
1 2                         so I need array 3x3; for first row for value 1 I have two times value 3 and one time value 2
2 2                                                                                    2 I have two times value 1 and one time value 2 and one time value 3
3 2                                                                                    3 I have two times value 2 and one time value 3 
3 2              so my result matrix will be      1   2  3
3 3                                                       1  0  1  2
2 3                                                       2  2  1  1
2 1                                                       3  0  2  3
2 1
1 3
1 3
Maybe its more clear

Similar Messages

  • How to create array with "n" elements...

    Hy, how can i create a array with "n" elements ?

    i know, but the thing is: the other methode (which
    one isn't developed fom me) needs an Object Array
    (Object []) to work correctly...then take a look into the method toArray() of the Collection interface.
    thats why i need this gay "object Array"....I think it would be wise to avoid that adjective in this context and meaning.

  • Sorting array with VBS

    I am reading data from file to array with For Next loop. I get the data to array but when I try to pass this unsorted array to bubblesort function I get type mismatch error. I don't understand why.
    'This causes type mismatch
    arrTestArray = BubbleSort(arrTestArray)
    Function BubbleSort(arrValues)
        Dim j, k, Temp
        For j = 0 To UBound(arrValues) - 1
            For k = j + 1 To UBound(arrValues)
                If (arrValues(j) > arrValues(k)) Then
                    Temp = arrValues(j)
                    arrValues(j) = arrValues(k)
                    arrValues(k) = Temp
                End If
            Next
        Next
     BubbleSort = arrValues
    End Function

    I should also note that in Office VBA and in VB6 we can do this:
    Dim someArray(1 To 10)Dim someArray(-3 To 12)
    Dim someArray(-10 To -1)This is where the need for LBound comes from. If you generate an array like this in Office and pass it to VBScript then you need to use LBound.
    The misuse of UBound -1 is a takeoff on using Length for the limit.
    for I = 0 to A.Length -1
    which would be better stated like this:
    i=0
    while(i < a.length)
       i = i - 1
    wend
    Of course VBScript doesn't not have an array length function.
    ¯\_(ツ)_/¯

  • Store XML node value into an array with node element name

    Hi,
    I have the following code that displays the node element with the
    corresponding node value. I want to store the values in an array in
    reference to the node name.
    i.e.
    XML (my xml is much bigger than this, 300 elements):
    <stock>
    <symbol>SUNW</symbol>
    <price>17.1</price>
    </stock>-----
    would store the following:
    *data[symbol] = SUNW;*
    *data[price] = 17.1;*
    Thanks in advance,
    Tony
    test.jsp
    Here's my source code:
    <html>
    <head>
    <title>dom parser</title>
    <%@ page import="javax.xml.parsers.*" %>
    <%@ page import="org.w3c.dom.*" %>
    <%@ page import="dombean.*" %>
    </head>
    <body bgcolor="#ffffcc">
    <center>
    <h3>Pathways Info</h3>
    <table border="2" width="50%">
    <jsp:useBean id="domparser" class="dombean.MyDomParserBean" />
    <%
    Document doc = domparser.getDocument("c:/stocks/stocks.xml");
    traverseTree(doc, out);
    %>
    <%! private void traverseTree(Node node,JspWriter out) throws Exception {
    if(node == null) {
    return;
    int type = node.getNodeType();
    switch (type) {
    // handle document nodes
    case Node.DOCUMENT_NODE: {
    out.println("<tr>");
    traverseTree
    (((Document)node).getDocumentElement(),
    out);
    break;
    // handle element nodes
    case Node.ELEMENT_NODE: {
    String elementName = node.getNodeName();
    //if(elementName.equals("MOTHER-OCC-YRS-PREVIOUS")) {
    //out.println("</tr>");
    out.println("<tr><td>"+elementName+"</td>");
    NodeList childNodes =
    node.getChildNodes();     
    if(childNodes != null) {
    int length = childNodes.getLength();
    for (int loopIndex = 0; loopIndex <
    length ; loopIndex++)
    traverseTree
    (childNodes.item(loopIndex),out);
    break;
    // handle text nodes
    case Node.TEXT_NODE: {
    String data = node.getNodeValue().trim();
    //if((data.indexOf("\n")  <0) &#38;&#38; (data.length() > 0)) {
    out.println("<td>"+data+"</td></tr>");
    %>
    </table>
    </body>
    </html>
    {code}
    *MyDomParserBean.java*
    Code: package dombean;
    {code:java}
    import javax.xml.parsers.*;
    import org.w3c.dom.*;
    import java.io.*;
    public class MyDomParserBean
    implements java.io.Serializable {
    public MyDomParserBean() {
    public static Document
    getDocument(String file) throws Exception {
    // Step 1: create a DocumentBuilderFactory
    DocumentBuilderFactory dbf =
    DocumentBuilderFactory.newInstance();
    // Step 2: create a DocumentBuilder
    DocumentBuilder db = dbf.newDocumentBuilder();
    // Step 3: parse the input file to get a Document object
    Document doc = db.parse(new File(file));
    return doc;
    {code}
    Edited by: ynotlim333 on Sep 24, 2007 8:41 PM
    Edited by: ynotlim333 on Sep 24, 2007 8:44 PM
    Edited by: ynotlim333 on Sep 24, 2007 8:45 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    I still need to store it in an array because its 300 elements in the XML stocks.
    I've done the following but its not working, i'm getting error codes. I think its an easy fix. I'd also like to pass a String instead of a .xml document b/c my xml is stored inside a DB. Any suggestions on that?
    <html>
    <head>
    <title>dom parser</title>
    <%@ page import="javax.xml.parsers.*" %>
    <%@ page import="org.w3c.dom.*" %>
    <%@ page import="org.*" %>
    </head>
    <body bgcolor="#ffffcc">
    <center>
    <h3>Pathways Info</h3>
    <table border="2" width="50%">
    <jsp:useBean id="domparser" class="org.MyDomParserBean" />
    <%
    Document doc = domparser.getDocument("c:/stocks/stocks.xml");
    traverseTree(doc, out);
    %>
    <%!
            public String element_store = null;
            public String[] stock_data = new String[400];
            private void traverseTree(Node node,JspWriter out) throws Exception {
            if(node == null) {
               return;
            int type = node.getNodeType();
            switch (type) {
               // handle document nodes
               case Node.DOCUMENT_NODE: {
                 out.println("<tr>");
                 traverseTree
                 (((Document)node).getDocumentElement(),
                 out);
                 break;
              // handle element nodes
              case Node.ELEMENT_NODE: {
                String elementName = node.getNodeName();
                element_store = elementName;
                 //if(elementName.equals("MOTHER-OCC-YRS-PREVIOUS")) {
                   //out.println("</tr>");
                 NodeList childNodes =
                 node.getChildNodes();     
                 if(childNodes != null) {
                    int length = childNodes.getLength();
                    for (int loopIndex = 0; loopIndex <
                    length ; loopIndex++)
                       traverseTree
                       (childNodes.item(loopIndex),out);
                  break;
               // handle text nodes
               case Node.TEXT_NODE: {
                  String data = node.getNodeValue().trim();
                  if((data.indexOf("\n")  <0) && (data.length() > 0)) {
                  out.println("<tr><td>"+element_store+"</td>");
                  out.println("<td>"+data+"</td></tr>");
                  stock_data[element_store]=data;
    %>
    </table>
    </body>
    </html>

  • Sort variant with WBS element...

    Dear All,
    I need to create a sort variant to use in AR01 report to capture the WBS element. But when i am creating the sort variant, it is saying this report can process tables only ANLAV, ANLB and ANLCV, here wbs element investment project field is there in ANLAV. but i want anothother field From ANLZ. What do i need to do...

    Hi,
    Hope you are looking for ANLZ fields.
    Go to OAVI and create your own sort version.
    There for WBS elemant, add table name as ANLZ and field name as PS_PSP_PNR2  /  IPSNR and press enter
    SAVE it.
    This will definetely work out.
    Thanks,
    Srinu

  • Auto-indexing is slow for arrays with 1 dimensions

    Hi,
    I was looking at the performance of operations on all individual elements in 3D arrays, especially the difference between auto-indexing (left image) and manual-indexing (right image, calling "Index array" and "Replace array subset" in the innermost loop). I'm a bit puzzled by the results and post it here for discussion and hopefully somebody's benefit in the future.
    Left: auto-indexing; right: manual-indexing
    In the tests I added a different random number to all individual elements in a 3D array. I found that auto-indexing is 1.2 to 1.5 times slower than manual-indexing. I also found that the performance of auto-indexing is much more dependent on the size the dimensions: an array with 1000x200x40 elements is 20% slower than an array with 1000x40x200 elements. For manual-indexing there is hardly any difference. The detailed results can be found at the end of this post.
    I was under the impression that auto-indexing was the preferred method for this kind of operation: it achieves exactly the same result and it is much clearer in the block diagram. I also expected that auto-indexing would have been optimized in LabView, but the the tests show this is clearly not the case.
    What is auto-indexing doing?
    With two tests I looked at how auto-index works.
    First, I looked if auto-indexing reorganizes the data in an inefficient way. To do this I made a method "fake-auto-indexing" which calls "Array subset" and "Reshape array" (or "Index array" for a 1D-array) when it enters _every_ loop and calls "Replace array subset" when exiting _every_ loop (as opposed to manual-indexing, where I do this only in the inner loop). I replicated this in a test (calling it fake-auto-indexing) and found that the performance is very similar to auto-indexing, especially looking at the trend for the different array lengths.
    Fake-auto-indexing
    Second, I looked if Locality of reference (how the 3D array is stored in memory and how efficiently you can iterate over that) may be an issue. Auto-indexing loops over pages-rows-columns (i.e. pages in the outer for-loop, rows in the middle for-loop, columns in the inner for-loop). This can't be changed for auto-indexing, but I did change it for manual and fake-indexing. The performance of manual-indexing is now similar to auto-indexing, except for two cases that I can't explain. Fake-auto-indexing performs way worse in all cases.
    It seems that the performance problem with auto-indexing is due to inefficient data organization.
    Other tests
    I did the same tests for 1D and 2D arrays. For 1D arrays the three methods perform identical. For 2D arrays auto-indexing is 15% slower than manual-indexing, while fake-auto-indexing is 8% slower than manual-indexing. I find it interesting that auto-indexing is the slowest of the three methods.
    Finally, I tested the performance of operating on entire columns (instead of every single element) of a 3D array. In all cases it is a lot faster than iterating over individual elements. Auto-indexing is more than 1.8 to 3.4 times slower than manual-indexing, while fake-auto-indexing is about 1.5 to 2.7 times slower. Because of the number of iterations that has to be done, the effect of the size of the column is important: an array with 1000x200x40 elements is in all cases much slower than an array with 1000x40x200 elements.
    Discussion & conclusions
    In all the cases I tested, auto-indexing is significantly slower than manual-indexing. Because auto-indexing is the standard way of indexing arrays in LabView I expected the method to be highly optimized. Judging by the tests I did, that is not the case. I find this puzzling.
    Does anybody know any best practices when it comes to working with >1D arrays? It seems there is a lack of documentation about the performance, surprising given the significant differences I found.
    It is of course possible that I made mistakes. I tried to keep the code as straightforward as possible to minimize that risk. Still, I hope somebody can double-check the work I did.
    Results
    I ran the tests on a computer with a i5-4570 @ 3.20 GHz processor (4 cores, but only 1 is used), 8 GB RAM running Windows 7 64-bit and LabView 2013 32-bit. The tests were averaged 10 times. The results are in milliseconds.
    3D-arrays, iterate pages-rows-columns
    pages x rows x cols : auto    manual  fake
       40 x  200 x 1000 : 268.9   202.0   268.8
       40 x 1000 x  200 : 276.9   204.1   263.8
      200 x   40 x 1000 : 264.6   202.8   260.6
      200 x 1000 x   40 : 306.9   205.0   300.0
     1000 x   40 x  200 : 253.7   203.1   259.3
     1000 x  200 x   40 : 307.2   206.2   288.5
      100 x  100 x  100 :  36.2    25.7    33.9
    3D-arrays, iterate columns-rows-pages
    pages x rows x cols : manual  fake
       40 x  200 x 1000 : 277.6   457       
       40 x 1000 x  200 : 291.6   461.5
      200 x   40 x 1000 : 277.4   431.9
      200 x 1000 x   40 : 452.5   572.1
     1000 x   40 x  200 : 298.1   460.4     
     1000 x  200 x   40 : 460.5   583.8
      100 x  100 x  100 :  31.7    51.9
    2D-arrays, iterate rows-columns
    rows  x cols  : auto     manual   fake
      200 x 20000 :  123.5    106.1    113.2    
    20000 x   200 :  119.5    106.1    115.0    
    10000 x 10000 : 3080.25  2659.65  2835.1
    1D-arrays, iterate over columns
    cols   : auto  manual  fake
    500000 : 11.5  11.8    11.6
    3D-arrays, iterate pages-rows, operate on columns
    pages x rows x cols : auto    manual  fake
       40 x  200 x 1000 :  83.9   23.3     62.9
       40 x 1000 x  200 :  89.6   31.9     69.0     
      200 x   40 x 1000 :  74.3   27.6     62.2
      200 x 1000 x   40 : 135.6   76.2    107.1
     1000 x   40 x  200 :  75.3   31.2     68.6
     1000 x  200 x   40 : 133.6   71.7    108.7     
      100 x  100 x  100 :  13.0    5.4      9.9
    VI's
    I attached the VI's I used for testing. "ND_add_random_number.vi" (where N is 1, 2 or 3) is where all the action happens, taking a selector with a method and an array with the N dimensions as input. It returns the result and time in milliseconds. Using "ND_add_random_number_automated_test.vi" I run this for a few different situations (auto/manual/fake-indexing, interchanging the dimensions). The VI's starting with "3D_locality_" are used for the locality tests. The VI's starting with "3D_norows_" are used for the iterations over pages and columns only.
    Attachments:
    3D_arrays_2.zip ‏222 KB

    Robert,
    the copy-thing is not specific for auto-indexing. It is common for all tunnels. A tunnel is first of all a unique data space.
    This sounds hard, but there is an optimization in the compiler trying to reduce the number of copies the VI will create. This optimization is called "in-placeness".
    The in-placeness algorithm checks, if the wire passing data to the is connected to anything else ("branch"). If there is no other connection then the tunnel, chance is high that the tunnel won't create an additional copy.
    Speaking of loops, tunnels always copies. The in-placeness algorithm cannot opt that out.
    You can do a small test to elaborate on this: Simply wire "0" (or anything less than the array sizy of the input array) to the 'N' terminal.......
    Norbert
    PS: Auto-indexing is perfect for a "by element" operation of analysis without modification of the element in the array. If you want to modify values, use shift registers and Replace Array Subset.
    CEO: What exactly is stopping us from doing this?
    Expert: Geometry
    Marketing Manager: Just ignore it.

  • Multiplying a 1D array with a scalar

    Hello Everyone,
    I'm trying to turn on a back-to-back thyristor by sending a current pulse outputed from the DAQ. The delay of this pulse would depend on the line current. I have a forumla that relates the line current and the delay and that includes fixed values for capacitance and inductance, however, the voltage would vary (some numeric constant).The forumla is as follows:
    I = V(w*c-(1/w*L)(1-(2*alpha/pi)-(sin(2*alpha)/pi)); alpha is the delay  in radians, w is the angular  frequency  2*pi*60 rad/s, L and C are my inductor and  capacitor value respectively, V is the varied voltage, and finally I  is the current.
    Since V is a constant which can be detected all the time from the DAQ, I thought about desiging an array for the other terms that just depends on alpha which vary from 0 to 90 degrees or 0 to pi/2 radians. I called (w*c-(1/w*L)(1-(2*alpha/pi)-(sin(2*alpha)/pi)) to be F which is an array to have the different values of F for alpha 0 to 90 degrees , after that I want to multiply this 1 D array with V (scalar) to get a current array. I used searh array to compare the whole current array with an element (which would extracted from my circuit and in labview would be tested as a constant). Using the same index for the found current, I want to extract an alpha value from an alpha array.
    so basically, I want to multiply F by V to get I, then search through I and compare all the columns by a constant value, and then extract the value of alpha from the same index. I attached my vi, plz help 
    Attachments:
    look_up_table_generation.vi ‏20 KB

    Sure, here are the guts of the code. The loop on the left creates the lookup table.
    entering a current level will calculate the fractional index, then return the corresponding value from the x array. The "current value" output is basically the "current level" input coerced to the valid y-range of the lookup table.
    Note that threshold and interpolate do a linear interpolation only. It is also required that the function increases monotonically, if not there will be multiple solutions and it would need extra code to get them all.
    Message Edited by altenbach on 02-25-2006 01:00 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    lookup.png ‏12 KB

  • I'm using UDP Send to send an 1D arry with 3 elements. On the other side I'm using UDP Read to read my 1D arry with 3 elements but they are coming in a string for somereason.

    Using UDP send to send a data across a connection to UDP read data by using a Port and IP. The data I'm sending is 1D array with 3-elements. I'm taking the 1D array on UDP send side and converting to a string before I send out b/c UDP can not read an array. So I'm using "Array to Spreadsheet String" to and sending it.
    On the Other Side I'm using UDP Read to read the data by listing to a port and capturing the data. I'm receving the data but they are in string format instead of 3 spreate elements. So how can I change that to 3 elements instead of string?
    Any help would be grea
    tful,
    Thanks
    Attachments:
    udp_send_data.vi ‏54 KB
    UDP_read_data.vi ‏55 KB

    It is usually easiest to take any data and flatten it to string before sending.
    On the receiving side, use unflatten from string, using the original data type as template.
    You can do this with any kind of data (array of strings, array of numbers, booleans, complicated clusters, etc, etc), see attached code image.
    Flatten and unflatten is very efficient and does not change the data. For example there is no rounding or formatting loss.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    FlattenUnflatten.gif ‏7 KB

  • Unable to plot 1-D array with a cluster of 2 elements on an XY graph

    I'm Unable to plot a 1-D array with a cluster of 2 elements on an XY graph. The data appears at the input to the graph but nothing is plotted. I'm trying to plot a line connecting each point generated.
    Solved!
    Go to Solution.
    Attachments:
    TEST11.vi ‏13 KB

    Chuck,
    0. Do not post VIs with infinite loops! Change the True constant to a control.  One of the regular participants on these Forums has commented that using the Abort button to stop a VI is like using a tree to stop a car.  It works, but may have undesired consequences!
    1. Use a shift register on the For loop also.
    2. Inserting into an empty array leaves you with an empty array.  Initialize the array outside the loop to a size greater or equal to the maximum size you will be using.  Then use Replace Array Subest inside the loop.
    3. Just make an array of the cluster of points.  No need for the extra cluster.
    Lynn
    Attachments:
    TEST11.2.vi ‏11 KB

  • Sort an array with two fields

    i have an array with three fields: id, name and date.
    i want to sort it by name first and then date.
    the size of my array could be as large as 1 million.
    what could be the most efficient way to do so?
    tia!

    It's very inefficient to sort an array on "the fly".
    In that case at least use a linked list so you don't
    have to move all elements after the insertion point to
    make room for a new insert. But it's much better to
    sort afterwards when all elements are in the array.Use a TreeSet. A linked list will be slower than a TreeSet, I suspect.
    I believe that with a TreeSet, insertions will be somewhat slower (O(logN) vs O(c)), but the subsequent sorting of a linked list will be, what, at least O(NlogN) and possibly O(N^2)? And when you're inserting the first elements into the TreeSet, it should be closer to O(c) anyway, whereas the after-the-fact sorting of a LinkedList wouldn't have an advantage like that.
    Then if necessary extract an array out of the TreeSet when you're done creating/inserting elements.
    But really, use a database.

  • Equal elements in array

    Hi guys, I need to write a program that finds the longest sequence of equal elements in an array. For example: {7, 0, 4, 4, 0, 2, 2, 2} -> {2, 2, 2}. I've been trying tons of things and never get the correct result :(
    Here's my buggy code:
    int[] arr = {1, 3, 3, 3, 3, 8, 6, 6, 6, 9};
              int numberIs = 0;
              int count = 1;
              int cTemp = 1;
              int numTemp = 0;
              for (int i = 1; i < arr.length; i++){
                   if (arr[i] == arr[i - 1]){
                        numTemp = arr;
                        cTemp++;
                   if (arr[i] != arr[i - 1]){
                        if (arr[i] == arr[i - 1]){
                             numberIs = arr[i];
                             count++;
                   if (cTemp > count){
                        count = cTemp;
                        numberIs = numTemp;
              System.out.printf("Number is %d; repeated %d times", numberIs, count);
    I have a general idea what's wrong, but every solution I come up with fails... Need some help PLEASE, as I'll need this code working by March 31.
    P.S. since I'm still a noob, I don'want any import declarations, trying to keep it as simple as possible.

    You need a groupLengthCounter for keeping track of how long the current group you're examining isThat's what the int cTemp does.
    You also need a max for keeping track of how long the longest group you found so far.I tried to do that with int count
    Maybe also one to keep track of what the number was that made up that group (3 in your example)That's accomplished by int numberIs & int numTemp, compared to each other later
    Needs some work to make sure array[i+groupLengthCounter] stays within bounds, but I'll leave that to you to figure out.One of the biggest problems I've had so far, couldn't resolve it on my own. And believe me, I tried many times. Nothing yet... Because of the outOfBounds excepion I would get I use the array index i like this: (int i = 1; i < arr.length;...) and if (arr[i] == arr[i - 1]) making sure I'm within bounds.
    Arrays are my worst nightmare in Java :(

  • I need sorting VI that returns the sorted array element's positions in the unsorted array

    I need a VI that will very quickly (n log n) sort a 1D array of doubles.  This VI should not only output the sorted array, but for each of the sorted array elements, it should also output that sorted array element's position in the unsorted array.  So for example if the input array were:
    unsorted_array
    4.1
    2.3
    7.0
    5.6
    10.2
    Then the output arrays would be:
    sorted_array
    2.3
    4.1
    5.6
    7.0
    10.2
    indices_array
    1 (the value 2.3 is located at position 1 in the unsorted_array)
    0 (the value 4.1 is located at position 0 in the unsorted_array)
    3 (the value 5.6 is located at position 3 in the unsorted_array)
    2 (the value 7.0 is located at position 2 in the unsorted_array)
    4 (the value 10.2 is located at position 4 in the unsorted_array)
    This way I could generate the sorted_array using just the indices_array and the unsorted_array.  Has anyone written a nifty piece of code to do this?  I did some research on (n log n) sorting algorithms but most of them use recursion which I don't know how to do in LabVIEW.  It would also be nice to have an algorithm like this that could sort an array of strings.
    cheers,
    Richard

    Try something like the attached example (LabVIEW 7.0). I think it does what you need.
    (To understand the code, it is important to know that arrays of clusters are sorted by the first element in the cluster).
    Sort array itself sorts also array of strings, so you could just substitute, keeping the rest of the code the same.
    Sort array uses a variation of quicksort, so it should have about NlogN complexity.
    (If you think you only need the array of indices to later generate the sorted array, it does not make much sense to even do it. To get the indices, you need to sort the array anyway. You should just sort the plain array directly.
    Message Edited by altenbach on 07-13-2005 03:47 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    SortAndIndex.vi ‏26 KB

  • Lots of blank space when printing array with only last element printed

    I have a slight problem I have been trying to figure it out for days but can't see where my problem is, its probably staring me in the face but just can't seem to see it.
    I am trying to print out my 2 dimensional array outdie my try block. Inside the trying block I have two for loops in for the arrays. Within the second for loop I have a while to put token from Stringtokeniser into my 2 arrays. When I print my arrays in this while bit it prints fine however when I print outside the try block it only print the last element and lots of blank space before the element.
    Below is the code, hope you guys can see the problem. Thank you in advance
       import java.io.*;
       import java.net.*;
       import java.lang.*;
       import java.util.*;
       import javax.swing.*;
       public class javaflights4
          public static final String MESSAGE_SEPERATOR  = "#";
          public static final String MESSAGE_SEPERATOR1  = "*";
          public static void main(String[] args) throws IOException
             String data = null;
             File file;
             BufferedReader reader = null;
             file = new File("datafile.txt");
             String flights[] [];
                   //String flightdata[];
             flights = new String[21][7];
             int x = 0;
                   //flightdata = new String[7];
             int y = 0;
             try
                reader = new BufferedReader(new FileReader(file));   
                //data = reader.readLine();   
                while((data = reader.readLine())!= null)   
                   data.trim();
                   StringTokenizer tokenised = new StringTokenizer(data, MESSAGE_SEPERATOR1);
                   for(x = 0; x<=flights.length; x++)
                      for(y = 0; y<=flights.length; y++)
                         while(tokenised.hasMoreTokens())
                            //System.out.println(tokenised.nextToken());
                            flights [x] [y] = tokenised.nextToken();
                            //System.out.print("*"+ flights [x] [y]+"&");
                   System.out.println();
                catch(ArrayIndexOutOfBoundsException e1)
                   System.out.println("error at " + e1);
                catch(Exception e)
                finally
                   try
                      reader.close();
                      catch(Exception e)
             int i = 0;
             int j = 0;
             System.out.print(flights [j]);
    //System.out.println();

    A number of problems.
    First, I bet you see a lot of "error at" messages, don't you? You create a 21x7 array, then go through the first array up to 21, going through the second one all the way to 21 as well.
    your second for loop should go to flights[x].length, not flights.length. That will eliminate the need for ArrayIndexOutOfBounds checking, which should have been an indication that you were doing something wrong.
    Second, when you get to flights[0][0] (the very first iteration of the inner loop) you are taking every element from the StringTokenizer and setting flights[0][0] to each, thereby overwriting the previous one. There will be nothing in the StringTokenizer left for any of the other (21x7)-1=146 array elements. At the end of all the loops, the very first element in the array (flights[0][0]) should contain the last token in the file.
    At the end, you only print the first element (i=0, j=0, println(flight[ i][j])) which explains why you see the last element from the file.
    I'm assuming you have a file with 21 lines, each of which has 7 items on the line. Here is some pseudo-code to help you out:
    count the lines
    reset the file
    create a 2d array with the first dimension set to the number of lines.
    int i = 0;
    while (read a line) {
      Tokenize the line;
      count the tokens;
      create an array whose size is the number of tokens;
      stuff the tokens into the array;
      set flights[i++] to this array;
    }

  • Arrays with more than 2^31-1 (2147483647) elements?

    Hi,
    I'm working with very large datasets and would like to be able to process arrays with more than 2^31-1 elements. This limit seems to come about because Java requires a signed integer to be passed as a parameter to an array declaration, e.g.:
    Object bytes = new byte[2147483647]; // works
    Object bytes = new byte[2147483648]; // failsIs there any way to get around this?
    Thanks very much,
    - Davi

    Is there any way to get around this?What about creating a class that aggregatesseveral
    arrays and implements the List API?
    KajUnfortunately, many of the methods in the List
    interface depend on int indexes also. You would
    probably want these methods to use a long index
    instead.True. I should have said that he should mimic the behaviour of the List interface, but not implement it.
    Kaj

  • Crash when use indexe array with in place element structure

    Hello !
    I have a problem with in place element structure. I want index a waveform array (16 elements) and when i execute or save that labview close....
    I dont have problem with waveform array 15 elements or less, but i need index 16 elements...
    Thanks for your help !!!
    Solved!
    Go to Solution.
    Attachments:
    Test.PNG ‏8 KB

    I give you my code but it work because i used a waveform array with only 15 elements. I can't save or execute with 16 elements...
    So add it (like picture Test.png) and you will see.
    Thank you
    Attachments:
    Test.vi ‏25 KB

Maybe you are looking for

  • Pages 5.5 Header/footer alignment

    How to align text to the left in Pages 5.5 in all 3 boxes in header or footer?

  • Nokia N97 - Sneak Preview ;)

    Nokia N97 in production  Gadget Remember to mark all correctly answered questions as Solved. A forum is only as great as the sum of its parts, together we will prevail.

  • Need help with session state/item refresh

    I have an application that allows users to record productivity information for our employees. There are different types of work they have to do, so the form is in header/multiple-detail form and uses collections to handle all processing. In the heade

  • Tax code error in Depreciation Test run

    Hello Can anybody help me understand how I can get round the following: I am doing a test depreciation run, but against all the assets there is the same error, 'Tax code ** does not exist for jurisdiction code ****'.  I do not wish to maintain the ta

  • How to add another drive to striped RAID

    I have 2 1TB drives in a striped RAID. Now I would like to add a 3rd. Can I just drag it into the RAID array in Disk Utility?