Multidimensional arrays with enhanced for statement

hello, do you know if it is possible to use enhanced for loop with multidimensional arrays, and if yes, then how?
for example:
int[][] arr = {{1,2},{3,4}};
for(int i[][] : arr){
    doSomethingWith(i[][]);
}

The syntax is nice'n'easy:
void f(int[][] m) {
    for(int[] row : m) {
        for(int x : row) {
}

Similar Messages

  • Create 10 different TEXTFIELDS with a FOR statement

    Hello everybody, I,ve been trying to create 10 different
    TEXTFIELDS with a FOR statement, in order to apply different
    properties to each one. First I tried this code:

    Hi - your first one is closer; the problem is that you are
    only creating one TextField and merely changing the properties of
    the same one each time through the loop, and you are trying to add
    the same one 10 times to the stage.
    You probably want to do something closer to:

  • BUG: 10.1.3..36.73 Internal Compile Error with enhanced for loop/generics

    I get the following compiler error when using the Java 5 SE enhanced for loop with a generic collection.
    Code:
    public static void main(String[] args)
    List<Integer> l = new ArrayList<Integer>();
    l.add(new Integer(1));
    printCollection(l);
    private static void printCollection(Collection<?> c)
    for (Object e : c)
    System.out.println(e);
    Error on attempting to build:
    "Error: Internal compilation error, terminated with a fatal exception"
    And the following from ojcInternalError.log:
    java.lang.NullPointerException
         at oracle.ojc.compiler.EnhancedForStatement.resolveAndCheck(Statement.java:2204)
         at oracle.ojc.compiler.StatementList.resolveAndCheck(Statement.java:4476)
         at oracle.ojc.compiler.MethodSymbol.resolveMethod(Symbol.java:10822)
         at oracle.ojc.compiler.RawClassSymbol.resolveMethodBodies(Symbol.java:6648)
         at oracle.ojc.compiler.Parser.resolveMethodBodies(Parser.java:8316)
         at oracle.ojc.compiler.Parser.parse(Parser.java:7823)
         at oracle.ojc.compiler.Compiler.main_internal(Compiler.java:978)
         at oracle.ojc.compiler.Compiler.main(Compiler.java:745)
         at oracle.jdeveloper.compiler.Ojc.translate(Ojc.java:1486)
         at oracle.jdeveloper.compiler.UnifiedBuildSystem$CompileThread.buildGraph(UnifiedBuildSystem.java:300)
         at oracle.jdeveloper.compiler.UnifiedBuildSystem$CompileThread.buildProjectFiles(UnifiedBuildSystem.java:515)
         at oracle.jdeveloper.compiler.UnifiedBuildSystem$CompileThread.buildAll(UnifiedBuildSystem.java:715)
         at oracle.jdeveloper.compiler.UnifiedBuildSystem$CompileThread.run(UnifiedBuildSystem.java:893)

    Install the Service Update 1 patch for JDeveloper (using the help->check for updates), and let us know if this didn't solve the problem.

  • Problem with the FOR statement.....again!

    Hi everyone,
    Well I'm still trying to do a car slideshow using external
    files and can't seem to see the end. The current movie is here:
    http://www.virtuallglab.com/projects.html
    I also attach the code. My problem is I had originally set up
    an animation with 2 pictures sliding in with some text, and then
    wait 4 seconds before sliding out, and then next pictures and text
    would slide in and so on, using a setInterval.
    The problem is the FOR loop seems to skip the setInterval and
    the function "wait", so it just loops quickly and jumps to last
    picture, so on the example above, it just slides the last picture
    (i=9) and that's it!
    Can you not include another function within a FOR statement.
    Or is there a way to tell the FOR loop to wait until all motion is
    finished?
    Any help greatly appreciated
    import mx.transitions.*;
    import mx.transitions.easing.*;
    for (i=0; i<10 ; i++) {
    var picLeft = "pics/"+i+".jpg";
    var picRight = "pics/"+i+"b.jpg";
    var txtToLoad = "text/"+i+".txt";
    this.createEmptyMovieClip("leftHolder",1);
    leftHolder.loadMovie(picLeft,i,leftHolder.getNextHighestDepth());
    leftHolder._x = -200;
    leftHolder._y = 15;
    var leftTween:Tween = new Tween(leftHolder, "_x",
    Strong.easeOut, leftHolder._x, 10, 2, true);
    this.createEmptyMovieClip("centerHolder",2);
    centerHolder.loadMovie(picRight,i+"b",centerHolder.getNextHighestDepth());
    centerHolder._x = 180;
    centerHolder._y = 250;
    var centerTween:Tween = new Tween(centerHolder, "_y",
    Strong.easeOut, centerHolder._y, 15, 2, true);
    text._x = 600;
    myData = new LoadVars();
    myData.onLoad = function(){
    text.carText.text = this.content;
    myData.load(txtToLoad);
    var textTween:Tween = new Tween(text, "_x", Strong.easeOut,
    text._x, 420, 2, true);
    myInterval = setInterval(wait, 4000);
    function wait() {
    var leftTweenFinished:Tween = new Tween(leftHolder, "_x",
    Strong.easeOut, leftHolder._x, -200, 1, true);
    var centerTween:Tween = new Tween(centerHolder, "_y",
    Strong.easeOut, centerHolder._y, 250, 1, true);
    var textTween2:Tween = new Tween(text, "_x", Strong.easeOut,
    text._x, 600, 1, true);
    clearInterval(myInterval);
    ***************************************************************************************** ***

    There is no way to tell a for loop to wait. That is not what
    they do.
    The entire for loop will execute (if possible, and it doesn't
    enter some kind of continuous infinite loop) completely before each
    time the frame is rendered.
    If you want to spread things out over time you need to use
    the setInterval -- but not inside a for loop! If you do that you
    immediately set however many intervals as your loop has. In this
    case you will also assign the ids for those intervals to the same
    variable, effectively overwriting the value so you will never be
    able to clear most of those intervals.
    So you need to rethink you whole structure. Set up some kind
    of counter and limit like this:
    var slidesToShow:Number=10;
    var curSlide:Number=0;
    Then have your setInterval increment the curSlide each time
    it is called and check to see if it has shown all of them. That is
    where your "loop" comes in.
    As for the other part of your question -- yes you actually
    have two different issues going on -- again you cannot make a for
    loop wait for anything. So no there is no way to pause it while you
    wait for your tween to end. But you can be notified when a tween
    ends.
    Check out the documentation about the tween class in the help
    files. There you will find the onMotionFinished event. So you can
    set up one of those to start whatever needs to be started when the
    tween has finished.
    You should also use the MovieClipLoader class to load your
    images, because you have no idea how long it will take to load
    them. Using that class you get a nice event (onLoadInit) that tells
    you when the asset is ready to be used.
    Finally I'm thinking you might want to use setTimeout instead
    of setInterval. It only goes once, while setInterval repeats
    forever. So I would think your algorithm would be something like
    this.
    1. load external asset
    2. when ready animate in and set onMotionFinished handler
    3. when motion is finished start loading next asset and
    setTimeout for 4 seconds.
    4. when 4 seconds is up or the clip is loaded (which ever
    takes longer) go to 2 and repeat.
    If this is going to be run locally on a hard drive or CD you
    won't have any problem with the length of time it takes to load the
    external assets, but if it is over the web it will take time.

  • Finding the minimum with a for statement

    Ok so Ive got this program and I need to find the minimum value from the 10 values that are entered by a user, my problem is I cant figure out to initialize the variable minNum, Im not sure how to do it with a for loop, if I set it to zero, then zero will always be the minimum, so Im not sure how to make it so it takes the first value as the minimum then compares each value entered after that to see if the value is smaller, and I have to use a for loop for this problem, my professor specified which loop to use, so heres the code:
    import java.util.Scanner;
    public class Exercise52Chapt6
      public static void main(String[] args)
                Scanner scan = new Scanner(System.in);
                  int minNum;  // stores the minimum of 10 numbers
                           int number;  // stores the current input
                           for ( int i = 1; i <= 10; i++ )
                    System.out.print( "Enter an integer > " );
                                   number = scan.nextInt( );
                        if(number < minNum)
                        minNum = number;
              // process results by printing the minimum
              System.out.println( "The minimum is: " + minNum );
    }

    import java.util.Scanner;
    public class Test
      public static void main(String[] args)
                    Scanner scan = new Scanner(System.in);
                        int minNum=0;  // stores the minimum of 10 numbers
                          int number;  // stores the current input
                          for ( int i = 1; i <= 10; i++ )
                            System.out.print( "Enter an integer > " );
                                number = scan.nextInt( );
                                if(i==1){
                                    minNum = number;
                                    continue;
                                if(number < minNum)
                                    minNum = number;
                    // process results by printing the minimum
                    System.out.println( "The minimum is: " + minNum );
    }

  • How to traverse an array with a for-loop in this certain way...

    so I need to traverse an array starting from the first element, then from the last element, then the second element, then the second last element, then third element and so on... in a for loop
    how would that look in code?
    Any help would be appreciated, thanks!
    Edited by: inspiredone on Apr 4, 2008 6:34 AM

    Wow, that's a really clever and elegant way to do it promethuzz. I actually came up with something already before I read your post so yeah don't worry about me copying or anything. Mine is not as elegant/efficient and I definitely like yours a lot more but I will just share it anyway...it looks pretty similar to the second algorithm The_Matrix has provided. I figured this out from thinking how quicksort compares its pivot with the two indexes...
        int front=0;
        int back = a.length - 1;
        int counter =0;
        boolean switchflag = true;
        while(front<=back)
          System.out.println(a[counter]);
          if(switchflag)
            counter = back;
            front++;
            switchflag = false;
          else
            counter = front;
            back--;
            switchflag = true;
        } Anyways, thanks a lot for you guys help, promethuzz, The_Matrix, and newark.
    Edited by: inspiredone on Apr 4, 2008 11:25 AM
    Edited by: inspiredone on Apr 4, 2008 11:27 AM

  • Other events interfere with abort for state machine started by an event

    In the attached VI there is a state machine that is triggered by a boolean “start” change event.  There is also a boolean “stop” that stop the state machine, a numeric “voltage” that has an event handler and a boolean “exit” that has an event handler.
    The stop button works as expected unless if the voltage value is changed before the stop button is pressed.  I was thinking this might be because there is an event for the voltage value change but there is also an event for the exit button value change and the problem does not occur if the exit button is pressed before stop.
    If anyone could explain the reason I am only running into the problem with the voltage value change and/or how to properly implement the stop/abort function I would appreciate it!
    Thanks,
    Dave (LabVIEW 7.1)

    Well that certainly solves the problem I was having!  The case in a while in a case in a while reminds me of the 10-level deep if statements I used to end up when starting C programming.  I guess the inner case/while are required for the state machine and the outer while is required for the Producer / Consumer.  I always find myself thinking in terms of "if/then" statements and the case/comparison took the place of that. 
    Regardless, problem solved.  If anyone has tips on how to make it (attached) look better, please post them!
    Lynn, I wasn't quite sure about your instructions on passing the exit and stop commands through the queue.  I went with the idea of keeping the long-running loop separate.  I know I still have a bit more to work out such as use of exit button while state machine is running, and the stop button only works in between state machine iterations.
    Message Edited by davey31415 on 11-27-2006 07:04 PM
    Attachments:
    PowerfoldMeasStat.vi ‏158 KB

  • Row operation on array with a For Loop

    Hi,
    I'm working with a large one dimensional column array. I'm trying to do the following
    for i=1:size(A)/2
    B(i,: ) =A(1+(i-1)*2:i*2)
    So, for example if
    A=          
    0
    1
    2
    3
    4
    5
    6
    7
    then
    B=             
    0 1
    2 3
    4 5
    6 7
    My approach was to use an array subset block inside the for loop to select a number of elements but I'm not sure how to transpose the selected elements into a new row to create the new array B. Is there a more straightforward approach?
    Thanks,
    Mike
    Solved!
    Go to Solution.

    try experimenting with the reshape array feeding it your input array and re-sizing it to output a 2d aray. It is much faster than using a For loop becuase the data never gets moved and LV just changes the array dimensions and updates the stride.
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Multidimensional array with start-job

    Hi! I'm trying to improve a script that will read in a CSV file to an array, divide it up to 4 chunks. So I will have 4 arrays and inside each array I have properties for computername, ip addresses and so forth. ($arrComputers[0][56].ComputerName)
    So what I want to do is:
    # Send 1 chunk array at a time to a Start-Job. 1 chunk consits of 100 computers.
    # Read each object,  $arrComputers[index][row].Status ,
    # If Status says "OK" don't continue to check, Else continue to fetch info and write back to
    $arrComputers[index][row].<property>
    So for I've only gotten to 
    $Script={
    Param($comp)
    <Do Check, Read and Write for each computer here>
    for($i=0;$i -lt 4;$i++)
    $compCollection[$i] | Start-Job -ScriptBlock $Script -ArgumentList ($compCollection[$i]
    I hope I have been clear what I'm trying to do. This is my first time trying it, so wouldn't surprise me if you guys got a better idea how to achieve what I want or what I've done wrong. I'm all ears and also to pointers to guides and such where I can read
    up more about advanced powershelling. 

    $computerlist | 
         ForEach-Object{
             Start-Job -Script $script
    -ArgumentList $_
    but
    $script={Param($computer)
    if($computer.Status -eq "OK"){
    #Do Nothing
    else
    #Do Something
    $computer.Status = #Assign new value
    #write back the same chunk it derived from.
    for($i=0;$i -lt 4;i++){
    $computerlist[$i] |
    ForEach-Object{
    Start-Job -Script $script -ArgumentList $_

  • Multi-dimensional array with dynamic size - how to?

    Hi
    I have a CONSTANT number of buckets. Each of them has to take a VARIOUS number of data series. The data series have one VARIOUS length per bucket. I'd like to index the buckets like an array to loop over them.
    So basically I need something like a multidimensional array with constant first dimension (bucket index), but dynamic second (data series index within bucket) and third (data point index within data series) dimension. What's the best way to do so?
    I should also remark that data series can get really big.
    Thanks in advance and best regards,
    Michael

    Hi Michael,
    the usual way is to use an array of cluster.
    Put your "2nd" and "3rd" data into a cluster and then make an 1D array of that cluster...
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • When will Office 2013 Offline File Cache for IE add in work with Enhanced mode?

    The Office 2013 Document Cache Uploader IE Plugin is incompatible with IE 11 running in enhanced mode.
    I read that enhanced security mode was enabled by default in Win8 so Microsoft can collect information and advise third party plug-in developers they need to update their stuff to work with it.  Then in November, Microsoft started shipping Win8 with enhanced
    security disabled.  But Win8.1 now ships with enhanced mode enabled...   But... Microsoft's own plug-in with the latest versions don't work with it.  The solution / workaround is to disable enhanced protection mode.  (I don't see this
    as a solution for me, my last virus infection because of insecure IE cost me over $400 to fix.)  When are you going to fix your own stuff?  Or will you retire it like a bunch of other goodies ripped out of Win8.  And Server 2012.  And Exchange
    2013........Lastpass.com has their plug-in working with enhanced mode... Why can't you fix it?  Should not be that tough to fix and to include it in a Office update....

    Hope there will be a fix soon....This should not be marked as 'answer'.  You simply state the fact that it is broken as I did and to disable IE Enhanced (warning/warning) and that is not an answer or a workaround..
    Somebody please at least look at it and come up a quick and cheap, down and dirty way to add this to the trusted zones so it will work?  then you can mark as answer.  Everyone there at Microsoft sitting around waiting for someone else
    or other department to do it.  Lastpass make it work, Logmein make it work, but Microsoft resting on their laurels .......My gosh, I paid $439 for a copy of Office Pro 2013 Professional to upgrade my Office 2010 and it does not work as well as 2010 did? 
    In this respect, the product is a Lemmon.  I already moved to the cloud for Exchange like they wanted me to, by crippling connection with this to my church's Exchange 2003 server.
    It seems the master plan behind this release is to disable function with Server2003 to drive more Exchange server or Cloud hosting sales.  Please make sure the product does what it did before, before you take my money and turn off the lights on important
    feature oversites.
    Any way to hack into Office 2010 and load its cache uploader to run in enhanced zone, or put a link or dll in the trusted zone to make this feature work again?  Can someone at Microsoft at least get it on the project board or bump it up a hundred spaces
    on priority list?  Maybe offer a bonus to the programmer that fixes it.  A weekend on the hiking trail or kayak excursion, or rock-climbing pass..  Microsoft guys like that outdoors kinds of stuff and will work like crazy to get it.

  • Synthesis bug with SV packed multidimensional array slices

    I've been using SV packed multidimensional arrays to do things like representing a bus which is many bytes wide, e.g. a 128-bit bus can be declared like this:
    logic [15:0] [7:0] myBus;
    You should be able to write "myBus[15:8]" to get the upper 64 bits (8 bytes) of this 128-bit wide packed value. However, I've found that in some expressions this produces some very buggy behavior. I've reduced it to a simplified example, with comments to show what works and what doesn't.
    `timescale 1ns / 1ps
    module sv_array_select (
    input logic sel,
    input logic [3:0] [1:0] i,
    output logic [3:0] outA,
    output logic [3:0] outB,
    output logic [3:0] outC
    // Works; equivalent to assign outA = {i[1], i[0]};
    assign outA = i[1:0];
    // Works; equivalent to assign outB = {i[3], i[2]};
    assign outB = i[3:2];
    // FAILURE
    // Synthesizes to equivalent of:
    // assign outC[2:1] = sel ? i[2] : i[0];
    // assign outC[3] = 1'bZ;
    // assign outC[0] = 1'bZ;
    assign outC = sel ? i[3:2] : i[1:0];
    endmodule
     I get this result in Vivado 2015.2 and 2013.2, haven't tried other tool versions.

    ,
    Yes, I can see that incorrect logic is getting generated by the tool.
    I will file a CR on this issue and will let you know the CR number.
    Thanks,
    Anusheel
    Search for documents/answer records related to your device and tool before posting query on forums.
    Search related forums and make sure your query is not repeated.
    Please mark the post as an answer "Accept as solution" in case it helps to resolve your query.
    Helpful answer -> Give Kudos
     

  • Working with MultiDimensional arrays

    Hi,
    Just wondering if anyone could help with a problem Im
    having with multi-dimensional arrays in Java:-
    I want to create a multi-dimensional array (e.g. 3 dimensions). I know this can be defined by code such as:-
    int[ ][ ][ ] my_array = new int[10][10][10];
    (would create a 10x10x10)
    My problem is that I want to address the array with indexes that aren't known at compile time, trying to do this causes an error:-
    e.g. my_array[0][0][0] = 1; is ok (i.e. the element at 0,0,0 is set to 1)
    but if the indexes 0,0,0 are replaced by the return value of some function,
    e.g.
    my_index1 = generateIndex(x, y, .... etc);
    my_index2 = generateIndex(a, b, ...etc);
    my_index3 = generateIndex(f,g, .. etc);
    (where generateIndex is some function that returns an integer)
    and the array element set with
    my_array[my_index1][my_index2][my_index3] = 3;
    This generates an error. I know that this problem can be overcome through the use of pointers in C++ but since Java doesn't use pointers, im a bit stuck!
    I have come across a method that overcomes this for a 1D array, using the setInt function of the Array class, e.g.
    Array.setInt(my_1Darray, 0, 1); (would set the first value of my_1Darray to 1);
    (i.e. Array.setInt(array_name, int index, int value);
    But I can't see how this works with multidimensional arrays.
    If anyone could shed any light on this problem, that would be great.
    Thanks,
    Peter

    public class NDArray {
            public static void main(String[] s) {
                    int[][][] _3D = new int[10][10][10];
                    for (int c = 0; c < 1000; c++)
                            _3D[rnd()][rnd()][rnd()]=rnd();
                    for (int i=0; i < 10; i++) {
                      for (int j=0; j < 10; j++) {
                        for (int k=0; k < 10; k++) {
                            System.out.print(_3D[i][j][k]);
                            System.out.print(" ");
                      System.out.println();
                    System.out.println();
            static int rnd() {return (int) (10*Math.random());}
    /* output (example):
    7 0 0 4 9 9 3 0 0 2
    0 1 8 9 6 0 0 0 0 0
    5 3 0 5 0 0 1 0 0 3
    5 6 0 5 0 0 3 0 0 0
    0 0 0 0 4 0 0 5 8 6
    0 9 0 9 0 1 0 2 0 0
    3 3 8 6 0 0 1 0 3 4
    9 6 7 0 0 0 3 6 6 3
    2 0 8 7 0 1 4 0 7 0
    8 0 4 4 3 0 0 5 4 0
    0 0 0 0 3 0 1 0 0 4
    9 0 8 9 1 0 9 0 9 0
    0 8 3 4 1 0 8 0 0 2
    3 0 0 7 3 3 0 5 0 0
    0 0 0 1 4 6 0 0 0 3
    3 5 8 5 8 0 8 2 0 4
    4 0 1 7 0 1 0 4 4 0
    6 0 5 0 0 4 0 8 1 0
    0 0 6 6 2 0 0 4 5 0
    0 6 7 0 4 0 7 5 0 0
    2 4 0 5 0 0 0 2 1 7
    0 6 0 9 0 0 6 1 2 0
    0 5 9 0 1 2 4 0 8 6
    0 0 8 0 0 3 3 8 0 0
    4 7 5 9 0 8 1 0 0 9
    2 0 0 3 0 0 8 3 0 7
    0 6 0 6 0 0 0 0 1 0
    0 9 9 8 4 2 0 0 7 2
    4 0 0 9 0 0 0 1 0 6
    7 0 6 5 2 3 7 8 0 2
    0 0 3 5 0 0 0 0 0 0
    3 0 0 0 0 2 0 0 6 0
    6 0 3 3 6 0 4 0 1 6
    0 0 7 2 0 8 0 0 0 0
    0 0 9 0 6 8 2 1 0 0
    9 0 4 1 3 9 3 2 7 7
    0 3 1 0 3 0 0 9 0 5
    0 0 0 0 6 0 4 8 0 5
    1 8 4 6 7 0 0 4 4 0
    0 4 8 0 0 0 6 0 4 0
    0 9 3 0 0 0 6 0 0 8
    6 8 2 9 6 0 0 7 9 0
    7 1 9 0 0 5 0 2 3 0
    0 0 0 0 9 9 0 7 0 9
    9 8 8 2 9 8 0 5 8 0
    2 3 0 4 0 4 1 0 6 9
    3 3 0 0 0 0 7 6 9 3
    6 2 2 1 0 5 8 3 0 6
    0 6 0 0 0 0 0 0 7 5
    0 6 0 0 0 3 3 0 2 0
    3 6 5 5 8 2 0 9 1 0
    8 0 7 0 9 0 9 0 2 0
    0 2 9 0 0 1 2 4 0 2
    3 1 0 2 0 0 0 0 0 0
    0 5 0 3 8 8 3 0 0 0
    9 0 9 0 5 1 0 9 5 0
    8 0 0 8 8 7 0 3 1 0
    4 0 0 0 1 8 0 9 0 5
    0 0 6 6 0 0 5 2 6 8
    0 4 0 9 0 0 2 0 0 3
    0 5 8 1 7 0 0 4 2 0
    6 5 0 0 2 0 6 8 8 7
    0 0 0 0 3 0 8 4 0 0
    2 3 3 0 0 7 6 8 0 4
    4 1 7 3 8 0 2 3 3 0
    1 5 0 0 4 1 3 7 3 1
    0 0 0 6 0 6 0 0 3 0
    3 7 0 4 5 9 5 5 0 8
    3 8 6 4 0 0 0 1 6 0
    0 0 2 0 2 9 0 0 0 5
    0 5 6 0 5 5 4 0 6 7
    0 2 2 0 9 7 4 2 9 0
    4 0 5 4 8 3 0 0 2 0
    0 0 9 3 3 0 8 8 7 0
    0 7 9 7 0 0 0 7 1 0
    2 0 0 0 5 8 2 0 0 5
    2 4 9 6 6 0 0 0 6 0
    0 6 6 7 0 2 0 0 5 2
    0 9 0 4 8 5 1 0 7 6
    0 0 7 0 4 0 3 8 0 9
    9 4 0 0 0 4 0 0 0 5
    2 0 4 7 7 5 4 0 9 0
    0 0 1 0 5 0 1 0 6 0
    0 6 0 9 0 9 0 4 7 0
    5 9 6 6 2 8 8 4 1 4
    9 7 3 2 7 6 0 2 3 0
    3 1 5 0 8 0 0 0 0 0
    9 0 0 3 0 8 7 0 4 0
    8 6 6 4 0 4 6 4 5 0
    0 0 0 0 0 4 4 0 0 9
    8 8 0 2 0 0 0 1 0 0
    6 2 1 1 9 0 5 1 0 0
    0 9 1 0 6 0 4 0 0 0
    9 4 0 3 0 1 0 7 6 0
    0 9 0 7 8 6 0 5 0 0
    0 8 8 9 0 5 7 0 0 0
    0 4 5 1 6 0 5 2 9 3
    6 0 0 0 0 0 0 9 1 0
    5 9 1 9 2 5 3 0 0 9
    2 9 5 1 7 0 0 0 9 0
    */Seems to work just fine. How is your code different from mine?

  • I need help with my for loop in this array

    Ok well, I can't get my code to work. Also, please remember that this is just my draft so it isnt pretty. I will fix it up later so please look at it. The thing I want to do is look into the array for a time that matches what the user entered and return the toString() of that one. I know there is something wrong with my for loop but I cant figure how to fix it. please help. here is what i have so far:
    import javax.swing.JOptionPane;
    public class Runner
        public static void main (String[] args)
            String timeStr;
            int time, again, optiStr;
            Inbound[] in = new Inbound[25];
             in[0]=new Inbound ("",0,"On Time num0");
             in[1]=new Inbound ("",2,"On Time num1");
             in[2]=new Inbound ("",3,"Delayed num2");
             in[3]=new Inbound ("",4,"On Time");
             in[4]=new Inbound ("",5,"On Time");
             in[5]=new Inbound ("",6,"Canceled");
             in[6]=new Inbound ("",1,"Canceled num6");
             in[7]=new Inbound ("",8,"On Time");
             in[8]=new Inbound ("",9,"Delayed");
             in[9]=new Inbound ("",10,"On Time");
             in[10]=new Inbound ("",11,"Delayed");
             in[11]=new Inbound ("",12,"On Time");
             in[12]=new Inbound ("",13,"Delayed");
             in[13]=new Inbound ("",14,"On Time");
             in[14]=new Inbound ("",15,"On Time");
             in[15]=new Inbound ("",16,"On Time");
             in[16]=new Inbound ("",17,"Canceled");
             in[17]=new Inbound ("",18,"On Time");
             in[18]=new Inbound ("",19,"On Time");
             in[19]=new Inbound ("",20,"Canceled");
             in[20]=new Inbound ("",21,"On Time");
             in[21]=new Inbound ("",22,"Delayed");
             in[22]=new Inbound ("",23,"On Time");
             in[23]=new Inbound ("",24,"Cancled");
             in[24]=new Inbound ("",7,"On Time num24");
            do{
                timeStr = JOptionPane.showInputDialog ("In military time, what hour do you want?");
                time = Integer.parseInt(timeStr);
                if (time<=0 || time>24)
                 JOptionPane.showMessageDialog (null, "Error");
                 optiStr = JOptionPane.showConfirmDialog (null, "If you want Incoming flights click Yes, but if not click No");
                if (optiStr==JOptionPane.YES_OPTION)
    //(ok this is the for loop i am talking about )
                    for (int index = 0; index < in.length; index++)
                      if ( time == Inbound.getTime())
                   JOptionPane.showMessageDialog (null, Inbound.tostring());  //return the time asked for
    //               else JOptionPane.showMessageDialog (null, "else");
                }//temp return else if failed to find time asked for
    //             else
    //               if (optiStr==JOptionPane.CANCEL_OPTION)
    //                 JOptionPane.showMessageDialog(null,"Canceled");
    //              else
    //                {Outbound.run();
    //                JOptionPane.showMessageDialog (null, "outbound");}//temp
                  again=JOptionPane.showConfirmDialog(null, "Try again?");
            while (again==JOptionPane.YES_OPTION);
    }any help would be greatly appriciated.

    rumble14 wrote:
    Ok well, I can't get my code to work. Also, please remember that this is just my draft so it isnt pretty. I will fix it up later so please look at it. The thing I want to do is look into the array for a time that matches what the user entered and return the toString() of that one. I know there is something wrong with my for loop but I cant figure how to fix it. please help. here is what i have so far:
    >//(ok this is the for loop i am talking about )
    for (int index = 0; index < in.length; index++)
    if ( time == Inbound.getTime())
    JOptionPane.showMessageDialog (null, Inbound.tostring());  //return the time asked for
    Inbound.getTime() is a static method of your Inbound class, that always returns the same value, I presume? As opposed to each of the 25 members of your array in, which have individual values?
    Edited by: darb on Mar 26, 2008 11:12 AM

  • 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.

Maybe you are looking for

  • ABAP in update rule

    I have one code in the start routine of the update rule which i have copied below .Just to fetch 96000 record , the system is getting hanged. select       /bic/zemployee       /bic/zevent       /bic/zmatlsamp       material       /bic/zcustomer      

  • Bought iPod Shuffle as a gift - will it be linked to my email address

    I bought 3 iPod shuffles as gifts for people I do not know in a gift drive. When they register the product will it be associates with my email address? I have 3 iPods associated with this email address and I do not want to run into issues.

  • Macbook pro discharging batteries

    I have two Macbook pros (2,2) both work fine from ac and charge the batteries, however one was losing the charge much faster when not connected to ac. Battery %age dropped from 100% to 74% in 30mins. The other one takes nearly an hour for the same. T

  • New 21" iMac with SSD; panic loop after updating to 10.8.3

    I updated to 10.8.3 this morning without issues. Later in the day, the computer spontaneously restarted and now is in a panic loop. Safe boot doesn't work, but I did restart from a clone. I also started from the Recovery Disk and Disk Utility confirm

  • How to move or migrate whole directories between ASM disk groups?

    Hello everyone! I'm playing around with Oracle ASM and Oracle Database (11g R1), I'm a student. This is just for testing purposes. Computer specifications are: Processor: Intel Pentium 4 HT 3.00 Ghz. RAM Memory: 2 GB. Hard Disk: 250 GB O.S.: Windows