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++;

Similar Messages

  • How do I read text from specific rows and columns in a tree structure?

    How do I read text from specific rows and columns in a tree structure? In a table you can specify the cell to read from but I have not been able to figure out how to do this with a tree structure.

    You need to set two properties to activate the correct cell and then you can read it's string property.
    The positioning properties are the "ActiveItemTag" and
    "ActiveColNum" properties. With them you select the tree item by it's tag and the active column. The string can then be read from the "Cell String" property.
    MTO

  • Select row and column from header in jtable

    hello i have a problem to select row and column from header in jtable..
    can somebody give me an idea on how to write the program on it.

    Hi Vicky Liu,
    Thank you for your reply. I'm sorry for not clear question.
    Answer for your question:
    1. First value of Open is item fiels in Dataset2 and this value only for first month (january). But for other month Open value get from Close in previous month.
    * I have 2 Dataset , Dataset1 is all data for show in my report. Dataset2 is only first Open for first month
    2. the picture for detail of my report
    Detail for Red number:
    1. tb_Open -> tb_Close in previous month but first month from item field in Dataset2
    espression =FormatNumber(Code.GetOpening(Fields!month.Value,First(Fields!open.Value, "Dataset2")))
    2. tb_TOTAL1 group on item_part = 1
    expression =FormatNumber(Sum(CDbl(Fields!budget.Value)))
    3. tb_TOTAL2 group on item_part = 3 or item_part = 4
    expression =FormatNumber(Sum(CDbl(Fields!budget.Value)) + ReportItems!tb_TOTAL1.Value )
    4. tb_TOTAL3 group on item_part = 2
    expression =FormatNumber(Sum(CDbl(Fields!budget.Value)) - ReportItems!tb_TOTAL2 .Value)
    5. tb_Close -> calculate from tb_TOTAL3 - tb_Open
    expression =FormatNumber(Code.GetClosing(ReportItems!tb_TOTAL3.Value,ReportItems!tb_Open.Value))
    I want to calculate the value of tb_Open and tb_Close. I try to use custom code for calculate them. tb_close is correct but tb_Open is not correct that show value = 0 .
    My custom code:
    Dim Shared prev_close As Double
    Dim Shared now_close As Double
    Dim Shared now_open As Double
    Public Function GetClosing(TOTAL3 as Double,NowOpening as Double)
        now_close = TOTAL3 + NowOpening
        prev_close = now_close
        Return now_close
    End Function
    Public Function GetOpening(Month as String,NowOpen as Double)
        If Month = "1" Then
            now_open = NowOpen
        Else    
            now_open = prev_close
        End If
        Return now_open
    End Function
    Thanks alot for your help!
    Regards
    Panda A

  • 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

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

  • 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];

  • 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

  • Adding or Deleting Rows and Columns from Tables

    I have notices that you can't delete or add a row or columns from a table in iWeb without having problems.
    You may get two added or deleted.
    I should indicate that the table comes from Excel.
    Does anyone know of a work-around?

    Problem 1 - The sub-form 'Stds' was not configured for repeating rows.
    Problem 2 - The script was on the wrong event. The script should be on the 'change' event and not the 'initialize' event.
    Problem 3 - Which header row in which sub-form are you referring too?
    Steve

  • Importing rows and columns from Excel to Cluster and Array in Labview

    An excel table consist of  4 columns and variable number of rows, the first column is the position number and the other 3 columns are series of coordinates (X,Y,Z). I would like to import the excel table into Labview such that each row in the table will form a cluster which consist of the position number and the coordinates of each position and each formed cluster should converted to a 1D-Array(double).
    I would be glad if someone can tell me the best way to go about this or better still show me some examples because i am very new in Labview.
    Thanks
    Omoba

    The easy way would be to save the excel file as csv (colon seperated values) and load it into ascii via load spreadsheet file (use ; as delimiter).
    The more advanced way is to interface excel via ActiveX. Use the example finder and search for ActiveX to find some examples that interface excel (they should be shipped with LabVIEW).
    Post back if you have more detailed questions. 
    Felix 
    www.aescusoft.de
    My latest community nugget on producer/consumer design
    My current blog: A journey through uml

  • Remove JTable row and column in one event

    Hello,
    I 've using matrix table in one application.
    i need to remove both column and row in single event.
    For this i construct
    JTable(data[][], header[]);
    because dynamically increase data's and header's
    What can i do for this?

    Create a method that does:
    DefaultTableModel model = (DefaultTableModel)table.getModel();
    model.removeRow(...)
    model.setRowCount(...)
    Read the DefaultTableModel API for more information.

  • Goto row and column in a JTextArea

    Does anybody here know the correct procedure to get to a specific row and column in a JTextArea? I want to be able to do something like this:
    replace(char c, int row, int column) - where the original character at row,column will be replaced with c.
    I know that in C++, there is a windows console library that lets u do this, but there isn't one in java so I'm trying to get around it using a JTextArea.
    Thank you.
    Any Help/Comments/Ideas will be greatly appreciated.
    -Patrick

    JTextArea has a replaceRange method.
    John

  • 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

  • Excel & ActiveX: Insert arbitrary columns from 2D array and create graph problems

    Hi there,
    I want to insert data from either a 1D or 2D array from LabView into Excel and create graphs.
    I used the information from the following example:
    http://www.ni.com/example/28934/en/
    and was able to create a new Excel file (I'm using Excel 2010), writing data from an 1D array to a column in excel by creating a while loop and using the first element of the array to write it to a specific cell. I use the counter of the loop to write to the next cell when the loop starts over and always delete the first value, which I write to the cell, from the array until it is empty.
    Now I also would like to write a 2D array - so the first column in Excel should be the first column from the array and so. Here I cannot use the loop counter directly as Excel only counts 1,2,... for the rows, but uses A,B,... to count columns. Also I do not know in advance how many columns my 2D array will contain, so creating a lookup table like (A means 1, B means 2,...) is not really an option (except there really is no other way). Is there a possibilty to convert numbers into letters or some way to 'explain' to the program that column 2 in the array means column B in Excel for example, or is there a way to insert new columns?
    I figured out how to add new Worksheets and as I also need to create a certain number of Worksheets and I know that on standard 3 sheets are present when creating the file, I use the 'add' methode to create every new worksheets before worksheet 3 - I could use the same methode to create new columns in Excel, but so far I didn't find a methode to do so. Or is there a way to enter the whole 2D array at once?
    Then I'd like to create a graph (in case of the 1D arrays a bar plot, when using 2D arrays a 3D plot) to view the data. I found this example:
    http://www.ni.com/newsletter/51339/en/
    -> as I do not have the toolkit I'd like to do it using ActiveX directly, so I tried to do things like shown under the headline 'DIY ActiveX/.NET'
    I tried to load the snippet to a new Excel file but got the error message 'microsoft.office.interop.excel.dll not found' and hence the code is not working. That confuses me a little as I would guess when this dll is not present I cannot access Excel from LabView at all, though my understanding of what I'm really doing so far is quiet limited. ;-)
    Also - as far as I understand from the snippet - when creating a new chart object I should be able the create methodes for it, however when I do a right click on the chart object of an ActiveX Worksheet symbol there are none listed.
    To explain my problems better I added a snippet showing my two problems: The inner of the two while loops shows how I import a 1D array. In the outer loop I seperate the columns. I know that currently this is not working as all data end up in column A of the Excel sheet - so I would need to convert the number of the outer counter to A, B,... or find a different solution.
    Moreover on the snippet I placed an ActiveX Worksheet Property with the Chart Object - as I can see the difference to the Chart Object in the example code from the last link above is the color. However I'm not sure what that means and how to change/ solve this.
    And just to make sure - I know this way the VI does not run as the Chart Object is placed completely wrong - I just did it, so it is included in the snippet.
    I'd be thankful for any suggestions,
    Thanks!
    Solved!
    Go to Solution.
    Attachments:
    ExcelAreaScan.png ‏60 KB

    Hello everyone and thanks for the answers.
    I only have the LabView Student Edition available here - is the toolkit included in it too. How can I check if it is installed/ available and in case it is installed - where can I find it?
    Today I had time to take a look at the example
    Create via ActiveX Labview a XY Scatter plot graph on an excel sheet
    It almost does what I want in terms of creating a graph. The only problem I could not fix, is that in this example a sheet is created where only the graph is present. i'd like to add the graph to a previously created worksheet. Today I tried get this working but it seems I stilll don't really understand what I'm doing, I'll post a snippet of my code as soon as I can access the PC with LabView on it again.
    I also took a look at the other example for inserting 2D attays - it seems to be what I need, I just had no time so far to test it, I'll post an update when I could test it.
    Thanks for the help so far!

  • 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

  • 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

  • Ical doesn't show all calendars from icloud

    I don't all the calenders from icloud from my ipad 2 and ,my iphone 4, anyone has similar problem? and happen to know what steps I missed??

  • How to change Color of IMAGE Links

    Page properties is the only place I can find to change the color of LINKS. It works for text, but not for the border it automatically puts around a linked image. It's purple! Can't I make it white to blend in with the background? I have already chang

  • Need 900mHz G3 iBook Hardware Test CD/Program

    Greetings: I'm coming up empty with my written requests to Apple and search on eBay for a 900mHz G3 iBook Hardware Test CD which didn't come with my eBay purchased iBook. Can anyone point me to any sources for one? I hope being a pre-owned Mac user d

  • Unsupported Architecture

    Unsupported Architecture - Application executables may support either or both of the Intel architectures: i386 (32-bit) x86_64 (64-bit)   Other architectures may not be included in submitted binaries. Confirm that your Xcode project's build settings

  • Error running upgradeADF

    Hello, I am trying to get WebLogic 10.3.5 installed with the right ADF version in a Linux environment. Following information provided here - http://tompeez.wordpress.com/2011/06/25/upgrading-wls-10-3-5-with-adf-runtime-11-1-2-0-0-sherman-patch , all