Arrays[][] - row and column

Evening All...
Just a quick question regarding arrays. My program is working but I am trying to tidy it up.
public class Arrays{
static int firstArray[][]= new int [][] {{8,5},{9,3}};
static int secondArray[][]= new int [][] {{1,7},{4,8}};
static int thirdArray[][]= new int [][] {{0,2,4},{9,6,8}};
     static int fourthArray[][]= new int [][] {{2,1,0},{6,2,3}};
public static void main(String[] args)
     multiply(secondArray,firstArray);
     multiply(firstArray,thirdArray);
     public static void multiply( int[][] x, int[][] z)
     int array2[][] = new int [3][3];
     int 1r = x.length;
     int 1c = x[0].length;
     int 2r = z.length;
     int 2c = z[0].length;
     //for(etc...)
//      (Rest of program)
I want to edit the array.--------int array2[] = new int[3][3]; (up 9 lines)
Instead of specifying it as [3][3] for size.
I would like to say new int - length of row and column - im pretty sure it is similar to
the ints below - but cant seem to get the correct combination.
Thanks in advance for any help folks.

- you can use variables to specify array dimensions
- you can get the (1D) dimension of an array by using the "attribute" theArray.length . Knowing that a 2D-array is indeed an array of arrays, you can indirectky get the size oif the second dimension too:
public static void multiply( int[][] x, int[][] z) 
int array2[][] = new int [x.length][x[0].length];                  
}Of course this shoud be robustified to protect against x or x[0] being null (but in this case the multiplication is probably doomed anyway).
Regards,
J
Edited by: jduprez on Mar 14, 2011 10:45 PM
And please, in the future, use tags around code text, when posting code                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • How to get number of rows and columns in a two dimensional array ?

    Hello,
    What would be the simplest way to get number of rows and columns in a two dimensional array represented as integers ?
    I'm looking for another solution as For...Each loop in case of large arrays.
    Regards,
    Petri

    Hi Petri,
    See a attached txt file for obtaining two arrays with upper and lower index values
    Regards
    Ray
    Regards
    Ray Farmer
    Attachments:
    Get2DArrayIndex.txt ‏2 KB

  • Hi, how can i break the value for a row and column once i have converted the image to the array?????​??

    Hi, I would like to know how can i break the value for a row and column once i have converted the image to the array. I wanted to make some modification on the element of the array at a certain position. how can i do that?
    At the moment (as per attachhment), the value of the new row and column will be inserted by the user. But now, I want to do some coding that will automatically insert the new value of the row and the column ( I will use the formula node for the programming). But the question now, I don't know how to split the row and the column. Is it the value of i in the 'for loop'? I've  tried to link the 'i' to the input of the 'replace subset array icon' , but i'm unable to do it as i got some error.
    Please help me!
    For your information, I'm using LABView 7.0.

    Hi,
    Thanks for your reply.Sorry for the confusion.
    I manage to change the array element by changing the row and column value. But, what i want is to allow the program to change the array element at a specified row and column value, where the new value is generated automatically by the program.
    Atatched is the diagram. I've detailed out the program . you may refer to the comments in the formula node. There are 2 arrays going into the loop. If a >3, then the program will switch to b, where if b =0, then the program will check on the value of the next element which is in the same row with b but in the next column. But if b =45, another set of checking will be done at a dufferent value of row and column.
    I hope that I have made the problem clear. Sorry if it is still confusing.
    Hope you can help me. Thank you!!!!
    Attachments:
    arrayrowncolumn2.JPG ‏64 KB

  • Get the intersection when u know row and column in 2D array

    I am trying to get the intersection of the row and column and I am not able to do so......
    for example:
    123456789 <<These in array indicate the row
    255555555
    388888888
    499997999
    1234 above first element of each row represent columns........
    I want to get 7 which is the intersection of column 6 and row 4............Please help

    Hi Marlin..
    I am reading this after having done it in a very similar way....... thank you so much
    The problem is that the letters in languages can also be characters so they can be a,b..Language over{a,b}..if characters are not in numbers I am trying convert a,b into int internally however I dont know any data structure in java which will accept character as key and int as value......
    So I am stuck at modifying the part highlighted with ???? below
         public void startRecognizing()
              System.out.println("Begun recognizing language....");
              //Convert the word entered to letter array
              char [] wordEntered = word.toCharArray();
              // initialize variables
              currentState = startState[0]; //In the beginning the current state is start state
              /***************    For each letter entered    ********************************/
                   for (int w =0; w < wordEntered.length ;w++)
                        //Print element entered
                        currentChar = wordEntered[w];
                        System.out.println("Char "+currentChar);
                        //Convert to int
                        int currentIntChar;
                        //System.out.println("Char "+currentIntChar);
                        //Print current state
                   int currentIntState = Character.getNumericValue(currentState);
                        //System.out.println(" State "+currentIntState);
                        System.out.println(" State "+currentState);
                   // if characters are numbers this is fine below
                   if((Character.getNumericValue(currentChar)) != -1)
                                          currentIntChar = Character.getNumericValue(currentChar);
    /*** Get the new state based on element entered with the current state and get a new state***/ // column/char entered & row/state// The intersection is the new state which is made the current state for further process
                        //We add 1 since array starts from 0
                   currentState = transitionTable[currentIntState+1][currentIntChar+1];
                        System.out.println("  NEW current state "+currentState);
                   else
         //if letters in the language are not in numbers and are char ie a,b then convert a,b into int internally
                        java.util.Hashtable h = new java.util.Hashtable();
                        // STUCK HERE !!******************??????????
                        h.put(wordEntered[w], new Integer(w));
                        currentIntChar = ((Integer)h.get(wordEntered[w])).intValue();
              System.out.println("currentIntChar non numbers "+currentIntChar);
                        //We add 1 since array starts from 0
                   currentState = transitionTable[currentIntState+1][currentIntChar+1];
                        System.out.println("  NEW current state "+currentState);
              }//for main          
              finalDecision();
         }//startRecognizingThe assignment is due tomm morning...... I havent slept all night !

  • I need to take elements from within 2 nested for loops and place them in an array at the specific row and column that I need.

    I have tried intializing an array and replacing elements by specifying a particular row, and column, but in the end I get an array with only one element replaced, and I suspect that it is because as the for loops are running through their iterations each time the array is re-initializing. I have a simple vi that I will post below, it is not the exact situation that I have but is a good place for me to get some understanding. I have the row and column indexes being driven by the inner and outer loop iterations, which gives me the pattern I need. I am using the inner iterations as array elements. How do I set this up so that it works and d
    oes keep re-initializing my array.
    Attachments:
    Untitled.vi ‏26 KB

    I have fixed a number of things in your vi.
    You were right in thinking that the array was continuously re-initialized. To avoid this, use a shift register (right-click the loop border), which will pass the updated array into the next iteration.
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        
    Attachments:
    your_vi.vi.zip ‏13 KB

  • Row and Column detection of a 2D boolean array

    I use an array as showed by my example (LB8.2).
    Press a 1 or 0 in the array changes it's value and it gives
    back the Row and Column (that was changed).
    I use this to program a 22 channel patterngenerator (GPIB).
    It sends only the column (channel of patterngenerator) patterns, so that makes it faster.
    Has someone an idea if this row and column detection can be made simpler (faster)?
    Kind regards, Bernard
    Attachments:
    MyRowColDetection.vi ‏30 KB

    Here is a different way
    Tim
    Johnson Controls
    Holland Michigan
    Attachments:
    MyRowColDetection Rev TLE.vi ‏15 KB

  • Summing the Rows and Columns in an Array

    I am importing a 2-dimensional array of integers.(which is held in a 2-dimensional array)
    I need to store the row sums and column sums in separate 1-dimensional arrays.
    I can get the integers in and print out a list along with the grand total(sum of all).
    But, how do I pass each row's and each column's value in to my sumRow and sumCol methods to get the sum for each row and each column?
    Can I do the row and column summing in the same "for" statement where I calculate the "grand total"? Or am I making this more difficult than it is?
    Would appreciate any help.
    This is what I have so far:
    import java.awt.Graphics;
    import java.applet.Applet;
    public class TwoWayTable extends Applet {
         int numRows;
         int numCols;
         int [] [] cell;
         int [] rowSum;
         int [] colSum;
         int grandTotal;
    public TwoWayTable(int [][] data){
    grandTotal = 0;
    cell = new int [data.length][data.length];
    for(int i = 0; i < data.length; i++)
    for(int j = 0; j < data.length; j++){
         cell[i][j] = data[i][j];
    grandTotal += cell[i][j];
         System.out.println(cell[i][j]);
    System.out.println(grandTotal);
    public int sumRow(int [] data2){
         int rowaccumulator=0;
         rowSum = new int[data2.length];
         for(int numRows = 0; numRows < rowSum.length; numRows++){
         rowaccumulator += rowaccumulator + rowSum[numRows];
              return(rowaccumulator);
    public int sumCol(int [] data3){
         int colaccumulator = 0;
         colSum = new int[data3.length];
         for(int numCols = 0; numCols < colSum.length; numCols++){
              colaccumulator += colaccumulator + colSum[numCols];
              return(colaccumulator);

    Thanks for your input.
    I'll make the changes that you suggest.(after this)
    My output prints:
    4 6 3 8 21
    9 1 5 3 18
    13 7 8 11 39
    numbers are right, but I need to format the table
    the output needs to look like this:
    int int int int | rowsum
    int int int int | rowsum
    colsum colsum colsum colsum | total
    How do I do this?
    I have no idea?
    I'm supposed to call a "void setMargins( )" method to line this up, without
    using the exotic formatting in the IO library.
    I'm also supposed to use "public String toString( )"
    This is what I have so far:
    import java.awt.Graphics;
    import java.applet.Applet;
    public class TwoWayTable extends Applet {
    int numRows;
         int numCols;
         int [] [] cell;
         int [] rowSum;
         int [] colSum;
         int grandTotal;
    public TwoWayTable(int [][] data){
    cell = new int [data.length][data.length];     
    for(int i = 0; i < data.length; i++){
    for(int j = 0; j < data.length; j++){
         cell[i][j] = data[i][j];
    calcTotals(cell);
    for(int i = 0; i < cell.length; ++i){
    for(int j = 0; j < cell.length; ++j){
    System.out.print(cell[i][j] + " ");
    System.out.println(rowSum[i] + " ");
    for(int j = 0; j < cell.length-1; ++j){
    System.out.print(colSum[j] + " ");
    System.out.println(colSum[cell.length-1] + " " + (grandTotal));
         public void calcTotals(int [][] data2){
              grandTotal = 0;
              rowSum = new int[data2.length];                         
              colSum = new int[data2.length];                         
              for(int numRows = 0; numRows < data2.length; numRows++){
              for(int numCols = 0; numCols < data2.length; numCols++){
                   grandTotal += data2[numRows][numCols];               
                   rowSum[numRows] += data2[numRows][numCols];
                   colSum[numCols] += data2[numRows][numCols];

  • Help! Inserting a 1-D comment array into a 2-D string array at specified row AND column

    Hello everyone,
    I am writing a 2-D string array to excel and i need a way to add comments to my file like this:  
    SLAM    NAME    G Level    Comments
    1              RALF         26               
    1              RALF         26
    1              RALF         26
    1              RALF         26
    For some reason, i cannot specify a row AND column to write because: 
    When i use replace array subset it only replaces 1 element at my index. 
    When i use replace array subset with a loop, it creates empty spaces until it reaches the end of the array it is replacing.
    When i use Insert into array: i cannot wire 2 inputs for row and column.  
    In my complete VI i will need to write from row 1-1001, a different comment from 2-2002, a different comment from 3-3003, etc until a stop condition is met so i need to figure out how to do this programatically and not have it replace any elements outside of the range or it will override previous commetns. 
    I am at a loss of what to do. Any and all suggestions are greatly appreciated. 
    Thanks!
    Solved!
    Go to Solution.
    Attachments:
    array.vi ‏13 KB

    Hi proph,
    I made a small subtile change to yur VI and now it replaces all values of the 4th column…
    THINK DATAFLOW!
    Use shift registers when you need to propagate values from one loop iteration to the next!
    USE/LEARN DEBUGGING TECHNIQUES!
    There are tools like probes and highlight to understand your VI execution and to find problems…
    Go through all those free online courses offered by NI!
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome
    Attachments:
    array.vit ‏12 KB

  • Get Row and Column info from an Array Cluster

    I have an array with a cluster of 2 elements (string and double). Within my application, I am using the State Machine architecture with an Event Structure. When I click on a element within the cluster array, is there a way to retrieve the row and column? I seen the Coordinates within the Mouse Down event but I don't think that will work.
    Any ideas?
    Solved!
    Go to Solution.

    How To Return the Index of a Mouse-Select Array Element:
    https://decibel.ni.com/content/docs/DOC-6406
    Jean-Marc
    LV2009 and LV2013
    Free PDF Report with iTextSharp

  • Getting row and column of an array element

    Hi,
    I have an array of 24 rows and 24 column giving me a total of 576 elements. How do I get the row and column of a particular element in an array in LabView. E.g. If I have to write to element 127 how do I get the column and row in which element 127 is located.
    Regards,
    Harshil
    Solved!
    Go to Solution.

    Hi Harshil,
    maybe you only need to find the correct "address" of the element in your 2D array?
    Use something like this:
    Maybe you have to switch Row&Column output according to your numbering scheme...
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • Remove specific row and column from 2d array

    Hi,
    I would like to know how to remove the specific row and column from 2d array.
    for example, I have the original 4x4 array as below
    2 -1 -1 0
    -1 2 0 -1
    -1 -1 2 0
    -1 -1 -1 3
    let say that i want to remove row 2(bold) and column 2(bold), and the new 2d array should get as below
    2 -1 0
    -1 2 -1
    -1 -1 3
    Thanks.

    You can't remove elements of an array, it's fixed at a certain size once created. What you can do however is make a new array and only copy the things you want. Something like:public static void main(String[] args) {
        Integer[][] bar = new Integer[5][5];
        for (int i = 0; i < bar.length; i++) {
            Integer[] baz = bar;
    Arrays.fill(baz, i);
    System.out.println(Arrays.toString(baz));
    Integer[][] muu = new Integer[5][4];
    removeColumn(3, bar, muu);
    for (Integer[] mee : muu) {
    System.out.println(Arrays.toString(mee));
    Integer[][] smuu = new Integer[4][5];
    removeRow(3, bar, smuu);
    for (Integer[] mee : smuu) {
    System.out.println(Arrays.toString(mee));
    public static <T> void removeRow(int row, T[][] a, T[][] result) {
    if (row >= a.length) {
    throw new IllegalArgumentException("no row at " + row);
    for (int a_r = 0, result_r = 0; a_r < a.length; a_r++) {
    if (a_r == row) {
    continue;
    System.arraycopy(a[a_r], 0, result[result_r], 0, a[a_r].length);
    result_r++;
    public static <T> void removeColumn(int col, T[][] a, T[][] result) {
    for (int i = 0; i < a.length; i++) {
    if (col >= a[i].length) {
    throw new IllegalArgumentException("no column at [" + i + ", " + col + "]");
    for (int a_i = 0, r_i = 0; a_i < a[i].length; a_i++) {
    if (a_i == col) {
    continue;
    result[i][r_i] = a[i][a_i];
    r_i++;

  • How to preserve a row and column in numbers automatically.ie the cells are not consecutivecell a1 a3 etc

    working on a league table
    when sorting the league table ,I need to preserve the row and column
    I can preserve row and column by using the drop down menu on every cell,but would like to do it automatically(2 clicks to every cell)
    working in numbers
    yosemite 10.2

    This technique would be quite slow. Unfortunately, it's the only way I could think of if it's really an Excel file. If it's tab delimited file, you could read a whole thing into 2D array and work on Array instead of reading cell-by-cell.

  • Set maximum matrix row and column size

    I hope someone can help me with this. Is there any way to set the row and column size of a matrix control? I have not been able to find a solution. The only way I've been able to set the size is by resetting matrix to its previous state if the user inputs a value outside of the bounds I would like to set. This is done in the 'value changed' event case.
    The matrix is large and therefore I cannot increase the size of the control to be the maximum size and then hide the row and column index controls. These have to be displayed.
    Any suggestions or help would be greatly appreciated. Thanks in advance.

    Here's a quick and dirty way.
    Simply hide the index controls and replace them with some fake numeric controls and set the data range accoding to your requirements.
    In the attached example (LV8.0), the fake index controls are limited to 0..2, the array size is 5x5 and the displayed array portion is 3x3. Seems to work fine.
    (Of course you could add a bit more code to set the limits automatically based on the various sizes.)
    You could also make it more fancy and turn the entire thing into an Xcontrol.
    Message Edited by altenbach on 06-06-2007 05:32 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    LimitArrayControl.vi ‏18 KB

  • Search row and column for return value

    Dear Sir/Madam,
                               I have a problem for searching spreadsheet and hope you can help me out a bit.  Im pretty new to Labview and Im currently using Labview 8.0.  My task is to search the spreadsheet I have attached in row and column-wise, then return the corresponding value out.  I had an attempt in doing this as you can see from the vi that i have attached.  I try inputting the 'read from measurement file' into an array and using delete, index and search array I will be able to find the index value for the relevant row and column that i searched for by inputting them into an index array with the orginal array from the 'read from measurement file'.
                              So ultimately, when i enter a row value of 0.5 and a column value of 0.3, my output will be 1.688.
                              I can't see any mistakes in my logic but I getting really strange results, like I can read my data has been entered into an array but when i try deleting the first column and put it into another array, the orginal array with nothing deleted is outputted hence making my search to give out -1 value. So could you take a look please and give me any suggestion that can solve my problem or enhance the code a bit.  Thank you for your time.
    Best Regards,
    Coato
    P.s for some reason i can't attached the .lvm file of my data hence i have attached the excel version but i think you need to convert it back to .lvm for the 'read from measurement file' function to work.
    Attachments:
    Backswing compensation.csv ‏10 KB
    Backswing comnpensation2.vi ‏109 KB

    Your VI makes absolutely no sense to me, but maybe I don't understand what you are trying to do.
    You seem to have dynamic data with 6 signals and 48 points/channel. Now you reshape this into an array of dynamic data with 4x13 elements from which you slice out one row or column, resp. "delete from array" is NOT the correct tool to do this, use "Index array" with one index unwired to get a row or column as 1D array.
    So you end up with two 1D arrays of dynamic data that you search for DBL. It is difficult to understand how you want to search for an array element that corresponds to a scalar DBL value of 0.1. Your array elements are NOT DBLs but dynamic data, each containing many signals!
    There are two elements on all your data that are "3", the rest are zero. You will never find anything that is 0.1.
    Maybe you can convert your original dynamic data to a 2D array with "rows are signals" using "convert from dynamic data", then operate on the 2D array.
    Coato wrote:
                              So ultimately, when i enter a row value of 0.5 and a column value of 0.3, my output will be 1.688.
    Sorry, Please explain.
    Please make a VI containing a simple 2D aray as diagram constant that contains e.g. 5x5 typical values. Let us know what kind of result you expect from your algorithm..
    LabVIEW Champion . Do more with less code and in less time .

  • How can i open a PDF bank statement in numbers so that the rows and columns contain properly aligned data from statement?

    how can i open a PDF bank statement in "numbers" so that the rows and columns contain properly aligned data from statement?

    Numbers can store pdfs pages or clippings but does not directly open pdf files.  To get the bank statement into Numbers as a table I would open the bank statment in Preview (or Skim) or some pdf viewer.
    Then hold the option key while selecting a column of data.
    Then copy
    Then switch to numbers and paste the column into a table
    Then repeat for the other columns in the pdf document
    It would be easier (in my opinion) to download the QFX or CSV version from your bank

Maybe you are looking for

  • How can I use the update operation in a VC Model

    Hello experts, i try to to use the update operation in my VC model.  I have developed an AS wich return a table. Now i want to update a table row. So I add the update operation to my model. But it doesn´t work. I mapped all attribute between the tabl

  • Not able to connect to Jboss 4.2.3 from Jdeveloper 11.1.1.0

    I am using Jboss 4.2.3 and Jdeveloper 11.1.1.0 and trying to connect to Jboss from Jdeveloper, my OS is Windows vista. I started Jboss and tried creating a Application Server creation from Jdeveloper. Gave connection name as "youHomeApp", selected co

  • Music Error message

    Everytime I try to open music and sometimes just randomly I get an error message that says  SORRY!  The application Music (process com. motorola.music) has stopped unexpectedly.  Please try again.   Any ideas???

  • PROGRAM FOR CV01N

    Hi friends,    I want to crate BDC for CV01 transaction.    I am totally sonfused about this upload program...   Not able to apply logic for creating folders and creating documents under that folder..    Please help me out to get this BDC done... or

  • Why can't I see moire reduction tool in camera raw 8.1?

    Hi There, I have been happilly using the moire reduction tool in camera raw up until a day or 2 ago. For some reason the moire reduction panel no longer appears under the adjustment brush. The funny thing is that 1 dng file that I used the moire redu