Build a 2-dim array

Hello!
Now we have this problem: We start with a for-loop that runs as many times as there are numbers of signals. Then we want to create a 2-dim array. We know the numbers of columns but not number of rows... so the numbers of coumns can not be created dynamically like the number of rows. We thought of somethning with the "initialize array" but then one need to know both the numbers of rows and columns... any idea? Thank you and best regards.

Typically it ie easiest to use a shift register and build the array by adding new rows. (see attached, LV 7.0).
If you had something different in mind, please explain.
(If you expect the arrays to become very large, building arrays this way may cause slowdowns due to memory allocations.)
LabVIEW Champion . Do more with less code and in less time .
Attachments:
BuildArray.vi ‏33 KB

Similar Messages

  • How to fill up a 3-dim array?

    Hello!
    See the attached vi. We want to fill upp a 3-dim array. The pages are "number". If "true" is true then we want to insert the row that we build inside the case on page number "number". But the problem is that the new element is placed outside the 3-dim array because the pages are not the same size. How can this problem be solved? Maybe we should use "replace element" ? Does anyone have a tip or idea?
    Thank you and best regards.
    Attachments:
    trouble1.vi ‏51 KB

    Hello Ex-jobb,
    if you want to replace an element of an array, than the index has to be inside that array... Otherwise you have to add an element using build array.
    I changed your example a little bit.
    1) Adding a row with your "Replace Array element", but now using two index values. You may change the second index to your needs.
    2) Making the array constant "bigger" by setting a values at index [6,6,6]. You can NOT replace anything inside an empty array!
    Hope this helps,
    GerdW
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome
    Attachments:
    trouble1.vi ‏51 KB

  • System.arraycopy (2 dim array) and growth of 2 dim array

    Hi everybody
    I am working on a program which contains a module that can perform Cartesian product on number of sets.
    The code I have developed so far is :
    import java.lang.reflect.Array;
    public class Cart5 {
    public static void main(String[] args) throws Exception
    int pubnewlength;
    // declare SolArray
    int[][] solArray;
    // initialize solArray
    solArray=new int[1][4];
    // Use for method
    for (int ii=0 ; ii<4 ; ii++)
    solver(solArray,ii);
    // Print the array ?
    System.out.println("\n  The array was changed ... " );
    }  // End main
    public void solver(int Solarray2[][] , int abi)
    int[][]  A  =  {  {1,2,3,5},
                      {4,6,7},
                      {11,22,9,10},
                      {17,33}
      jointwoArrays(solarray2,A,abi);
    // some other operations
    } // End Solver method
    public void jointwoArrays(int solarray3[][] , int aArray[][],int indexA)
    int y,u;
    int[][] tempArray;
    // calculate growth of rows:
    pubnewlength=solArray3.length * aArray[indexA].length;
    //Fill TempArray
    y=solArray3[0].length;
    u=solArray3.length;
    tempArray=new int[u][y];
    // Use system.arraycopy to copy solArray3 into tempArray -- How ?
    // Change the size of arrow to proper size -- How ?
    solArray3 = (int[][]) arrayGrow(solArray3);
    // Join operation - Still under construction
    for(int i = 0, k = 0; i < tempArray.length; i++)
                   for(int j = 0; j < set3.length; j++)
                                     for (q=0;q<=2;q++)             
                                      { solArray3[k][q] = tempArray[i][q];}
                                     solArray3[k][q]= aArray[indexA][j];
                                     ++k;
    } // End jointwoArrays method
    // This module is from http://www.java2s.com/ExampleCode/Language-Basics/Growarray.htm
        static Object arrayGrow(Object a) {
        Class cl = a.getClass();
        if (!cl.isArray())
          return null;
        Class componentType = a.getClass().getComponentType();
        int length = Array.getLength(a);
        int newLength = pubnewlength;
        Object newArray = Array.newInstance(componentType, newLength);
        System.arraycopy(a, 0, newArray, 0, length);
        return newArray;
    } // End ClassI deeply appreciate your help with these 3 questions :
    1. How can I use system.arraycopy to copy my two dimensional array? I have searched but examples seem to be about one dim arrays.
    2. How can I change the "static Object arrayGrow(Object a)" , to grow my two dimensional array ?
    3. If you know any codes or articles or java code regarding cartesian products , please tell me.
    Thank you
    Denis

    1. How can I use system.arraycopy to copy my two
    dimensional array? I have searched but examples seem
    to be about one dim arrays.That's because you can't do it in one call. You need to create a loop which copies each 'row".
    >
    2. How can I change the "static Object
    arrayGrow(Object a)" , to grow my two dimensional
    array ?Why do you make it so complicated (generic). Make it take an int[][] array instead, and see the answer from above.
    >
    3. If you know any codes or articles or java code
    regarding cartesian products , please tell me.There are probably lots of them if you google.
    Kaj

  • How do I find the total number of elements in a multi dim array

    How do I find the total number of elements in a single or multi dim array?
    For example, a 2x3 array has 6 elements, and a 2x3x4 has 24. How do I compute this very easily - is there a single VI that does this?
    David
    Solved!
    Go to Solution.

    Use "array size" (array palette) followed by "multiply array elements" (numeric palette)
    (Works also equally well for 3D arrays and higher)
    For a 1D array, just use "array size".
    Message Edited by altenbach on 02-05-2009 05:57 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    NumberOfElements.png ‏3 KB

  • Create a 2-dim array dynamically

    Hello!
    I have had this problem here before but try one moore time :-)
    This is the thing: We have a text-file from which we read. This textfile can be different from time to time. From this textfile we can catch numbers of columns and numbers of rows that a 2-dim array should have. The problem is how one can create this 2-dim array dynamically? We have a while-loop that the program runs inside already. Must one use the while-loop to solve this problem? Or can one solve this with only a for-loop? Hope you understand how I mean :-) Best regards

    OK, I thought you want to read an array of the same size as the actual data in the file. You cannot read a 4x10 array if the file only contains data for a 3x5 array .
    Is the array size determined by the data in the file or by some other calculation?
    I would still read the entire file, then you can cut out a 2D subset using "array subset". This should not be a problem unless you have millions of array elements.
    LabVIEW Champion . Do more with less code and in less time .

  • In the attached vi, I have a 2-dim series of EMGs which I would like to connect with a 1-dim array. How can I do this?

    In the attached vi, de Y values are given for each time as a matrix. The problem is that the y values coming out have to be a 1-dim array, in order to connect this vi with another vi. How can I do this?
    Attachments:
    3-dim_Filter.vi ‏48 KB

    Hi,
    can you post your curve fitting .vi?
    I think you can do this with the reshape array.vi, and take the 2-D array, find out it's size, and multiply the two dimensions together to get the number of elements you need. That'll give you the array as 1-D, but whether it's in the correct order as you need it is another matter.
    It all depends on what the 2-D array is representing, and how much of it needs to go to the "other" .vi
    Hope that helps
    S.
    // it takes almost no time to rate an answer

  • Sort a 2-dim array?

    Hello!
    Now we have the following problem: We need to sort a 2-dim array depending on the values in the first column. Then we need the corresponding row to move to the right place too... we send a VI so you can see an example of how it might look like. So we need (in this case) the first column to sort so we get 1,2 and 3 and so on, so the last row should be 3,4, 392 and 2047.
    We think this might be easy to solve but we need some tip :-) Thank you and best regards.
    Attachments:
    sortarray.vi ‏17 KB

    I wrote my own 2D string array sort routine. It has come in handy many times. You can enter the column number that you want to sort on, and the entire rows are rearranged in the order of the column sort. If your array is numeric, you can easily change the vi to use numerics instead. One day I hope to make it polymorphic. Here it is:
    - tbob
    Inventor of the WORM Global
    Attachments:
    Sort2DArray(str).vi ‏63 KB

  • Shuffling 2-dim array

    Hello,
    i'm working on a game-project for school, now i need a shuffle of an 2-dim array where i've bound imageIcons to.
    public setRandom () {
    randomArray  = new int[numberRows][numberCollumns]; 
    for (int i=0; i<(numberRows-1); i++)
           for (int j=0; j<(numberCollumns-1); j++)
                  randomArray[i][j] = i;
    }So in the setRandom method i need a shuffle of the randomArray.
    Any ideas ?
    tnx

    i know, i've allready used it, but then i have multiple items and that's not good ...
    import java.util.*;
    public class Shuffle
         public static void main (String[]args)
              int numberRows = 3;
              int numberCollumns = 3;
              Random gen = new Random();  // Random number generator
              int [][] randomArray = new int [numberRows][numberCollumns]; 
              //--- Initialize the array to the ints 0-51
              for (int i=0; i<(numberRows); i++)
                   for (int j=0; j<(numberCollumns); j++)
                       randomArray[i][j] = i*numberCollumns+j;
                       System.out.print(randomArray[i][j]+"   ");
                   System.out.print("\n");
              for (int i=0; i<(numberRows); i++)
                   for (int j=0; j<(numberCollumns); j++)
                           int randomPositionR = gen.nextInt(numberRows);
                           int randomPositionC = gen.nextInt(numberCollumns);
                            int temp = randomArray[i][j];
                           randomArray[i][j] = randomArray[randomPositionR][randomPositionC];
                          randomArray[randomPositionR][randomPositionC] = temp;
                          System.out.print(randomArray[i][j]+"   ");
                   System.out.print("\n");
    }

  • 2 dim array of textField

    Hi
    i have a 2 dim array of textField and i want to fill it with some data
    for example:(this is a part of my applet)
    public void inti()
                Panel table_panel;
                TextField[] [] table1 = new TextField[5][3];
                table_panel = new Panel();
                table_panel.setLayout(new GridLayout(5,3));
                for(int i = 0; i <5; i++)               // for each row
                     for(int j = 0; j < 3 ; j++)       // for each coloum
                     table1[i] [j]= new TextField(); 
                             table_panel.add(table1[i][j]);
                     }// end for
                ClassType obj  ;
                ClassType obj  = new ClassType(x,y);
                table1= obj.fillData();       
    class ClassType{
                           //constructor...........
             public TextField[][] fillData()
              TextField[][] table= new TextField[5][3];
              String s = new String("A");
              for(int i = 0 ; i < 5 ; ++i)
                  for(int j = 0; j<3 ; ++j)
                   table[i][j] = new TextField(s);
              return table;
    }The problem here is:
    the applet is not intialized,should i dispaly table1 again after fillData
    Thanks for you help

    Thanks !
    This is my applet again:
    public void inti()
                Panel table_panel;
                TextField[] [] table1 = new TextField[5][3];
                table_panel = new Panel();
                table_panel.setLayout(new GridLayout(5,3));
                for(int i = 0; i <5; i++)               // for each row
                     for(int j = 0; j < 3 ; j++)       // for each coloum
                     table1[i] [j]= new TextField(); 
                             table_panel.add(table1[i][j]);
                     }// end for
                ClassType obj  ;
                ClassType obj  = new ClassType(x,y);
                table1= obj.fillData();       
    class ClassType{
                           //constructor...........
             public TextField[][] fillData()
              TextField[][] table= new TextField[5][3];
              String s = new String("A");
              for(int i = 0 ; i < 5 ; ++i)
                  for(int j = 0; j<3 ; ++j)
                   table[i][j] = new TextField(s);
              return table;
    }

  • How to sort a 2 dim Array ?

    hello
    I would like to sort a 2-dim array of double ( double[][])
    according to the 1st column
    It is possible to sort a 1st dim array (doubel[]) , but the method sort
    of the class Array doesn't work with double[][]).
    I have two (bad) solutions.
    1) Writing a sorting method but I would prefer using the sort' method of java which uses quicksort
    2) Creating a table of objects that implements Comparable but this would decrease performance
    Do you have a better Idea ?
    Thanks a lot

    I would like to sort a 2-dim array of double (double[][]) according to the 1st column
    Which is the first "column"? double[0][x] or
    double[x][0]?
    If it's the second one things get simple: your
    double[][] is really an array of objects where each
    object is an array of doubles. So all you need to do
    is write a custom Comparator for double[] to use the
    sort method:
    compare(Object obj1, Object obj2) {
    double[] d1 = (double[]) obj1;
    double[] d2 = (double[]) obj2;
    return d1[0] > d2[0];
    }Thanks for your so prompt answer.
    I can manage to put the data so that I sort the array according to x as in double[x][0]?
    But WHERE do I have to write the "compare" method ?
    Thanks

  • Two dim array

    hello
    it would be really nice if someone could help me with that.
    i am trying to sort an array and i have read that i can do that with a statement called sort(), but it doesn't seem to work.
    this is what i have tried:
    for(int i = 0; i < arr.length; i++)
           for(int j = 0; j < arr.length; j++)
               sort(arr[i][j]);
    }the error i get is:
    Exercise5W2.java [56:1] No method found matching sort(int)
    sort(arr[i][j]);
    ^
    1 error
    thanks for ur help!

    You can use the java.util.Arrays.sort() with and without
    the java.util.Comparator interface.
    First you sort all individual one-dim int arrays,
    then you sort the whole two-dim array.
    Here is how it goes:
    // 2-dim int array example
    int[][] twoDimIntArray = { { 4, 67, 45 }, { 23, 98, 3}, { 2, 68, 112}, { 333, 5, 21 } };
    // First you sort all individual 1-dim int arrays
    for (int i = 0; i < twoDimIntArray.length; i++)
        Arrays.sort(twoDimIntArray);
    // Then you sort the whole 2-dim array (with an house made Comparator)
    Arrays.sort((Object[])twoDimIntArray, new TwoDimIntArrayComparator());
    // Print out the result
    for (int i = 0; i < twoDimIntArray.length; i++)
    for (int j = 0; j < twoDimIntArray[i].length; j++)
    System.out.print(twoDimIntArray[i][j] + " ");
    System.out.println();
    // Here is the Compararor for 2-dim int array objects
    class TwoDimIntArrayComparator implements Comparator
    public int compare(Object o1, Object o2)
    int[] oneDimIntArray1 = (int[])o1;
    int[] oneDimIntArray2 = (int[])o2;
    // First integer of each array to be different,
    // return the comparison
    for (int i = 0; i < oneDimIntArray1.length; i++)
    if (oneDimIntArray1[i] > oneDimIntArray2[i])
    return 1;
    else if (oneDimIntArray1[i] < oneDimIntArray2[i])
    return -1;
    // All integers of the arrays are equal
    return 0;
    public boolean equals(Object obj)
    return false;

  • How to declare an expandable 2-dim Array

    Hi,
    How do I declare a 2-dim array that is can expandable with additional data?

    Look at this example (Catching the ideas of the other guis:
    e.g. create a Class Object which represents a Row
    class Row {
    ArrayList list = new ArrayList(10); //ten columns
    public Object getObject(int x) {
    list.get(x);
    public void setObject(Object o, int x) {
    list.add(x, o);
    Create an Table Object which is able to add your Rows-Objects
    class Table {
    ArrayList rows = new ArrayList();
    public void addRow(Row row) {
    rows.add(row);
    public Row getRow(int x) {
    return (Row) rows.get(x);
    public int getNrOfRows() {
    return rows.size();
    after this, you can fill your Objects like this
    Row row = new Row();
    row.setObject(0, "James");
    row.setObject(1, "Kirk");
    row.setObject(2, "Captain);
    Table table = new Table():
    table.add(row);
    Hope it helps a little bit

  • Converting ResultSet to Multi Dim Array

    Can anyone tell me an easy way of converting a ResultSet to a Multi-Dimensional array
    Thanks Gary

    convert it to a vector of vectors
    then convert the vector of vectors to a 2 dimensional array (array of arrays).
    you should be able to get the code to convert a vector of
    vectors into a 2 dim array from the web site.

  • Makepkg refuses to build due to depends array [solved]

    Makepkg refuses to build a package based on the contents of the depends array.  My understanding is that the contents of the makedepends array are needed to build, but the contents of the depends array are needed to run the software.
    Example, I want to build nvidia drivers for a kernel which I do not have installed.  I do have that specific kernel headers extracted (via a wrapper script) to $startdir/tar/lib/modules/${_kernver}/build
    I get the following error when I try to build:
    $ makepkg -s
    ==> Making package: nvidia-lts-ck 260.19.36-2 (Sun Jan 30 15:41:20 EST 2011)
    ==> Checking Runtime Dependencies...
    ==> Installing missing dependencies...
    error: 'kernel26-lts-ck>=2.6.32': could not find or read package
    ==> ERROR: 'pacman' failed to install missing dependencies.
    But if I comment out the depends array, it builds just fine.  What am I missed?
    PKGBUILD:
    # Maintainer: graysky <graysky AT archlinux DOT us>
    # Contributer: Eric Belanger <[email protected]>
    pkgname=nvidia-lts-ck
    pkgver=260.19.36
    _kernver='2.6.32-lts-ck'
    pkgrel=2
    pkgdesc="NVIDIA drivers for kernel26-lts-ck"
    arch=('i686' 'x86_64')
    url="http://www.nvidia.com/"
    makedepends=('kernel26-lts-ck-headers>=2.6.32' 'kernel26-lts-ck-headers<2.6.33')
    depends=('kernel26-lts-ck>=2.6.32' 'kernel26-lts-ck<2.6.33' "nvidia-utils=$pkgver")
    provides=('nvidia')
    license=('custom')
    install=nvidia-lts-ck.install
    if [ "$CARCH" = "i686" ]; then
    _arch='x86'
    _pkg="NVIDIA-Linux-${_arch}-${pkgver}"
    source=("ftp://download.nvidia.com/XFree86/Linux-${_arch}/${pkgver}/${_pkg}.run")
    md5sums=('2826484d87827351774449382e45c4a9')
    elif [ "$CARCH" = "x86_64" ]; then
    _arch='x86_64'
    _pkg="NVIDIA-Linux-${_arch}-${pkgver}-no-compat32"
    source=("ftp://download.nvidia.com/XFree86/Linux-${_arch}/${pkgver}/${_pkg}.run")
    md5sums=('6ebc5db9066e920b0b0e48377ce5eeb5')
    fi
    build() {
    cd "${srcdir}"
    sh ${_pkg}.run --extract-only
    cd ${_pkg}/kernel
    make SYSSRC=$startdir/tar/lib/modules/${_kernver}/build module
    package() {
    install -D -m644 "${srcdir}/${_pkg}/kernel/nvidia.ko" \
    "${pkgdir}/lib/modules/${_kernver}/kernel/drivers/video/nvidia.ko"
    install -d -m755 "${pkgdir}/etc/modprobe.d"
    echo "blacklist nouveau" >> "${pkgdir}/etc/modprobe.d/nouveau_blacklist-lts_ck.conf"
    install -D -m644 "${srcdir}/${_pkg}/LICENSE" "${pkgdir}/usr/share/licenses/nvidia-lts-ck/LICENSE"
    EDIT:  My bad... so accustomed to using the -s switch!  I now realize I need to makepkg -d to get this to work properly.
    Last edited by graysky (2011-01-30 20:59:19)

    Lone_Wolf wrote:tghe-retford, latest version of readline is      6.3.008-1 , is the mirror you selected up to date ?
    https://www.archlinux.org/mirrors/status/
    Finally managed to update it to 6.3.008-1, still gives the same error:
    root@archiso ~ # pacman -Q readline
    readline 6.3.008-1
    root@archiso ~ #arch-chroot /mnt /bin/bash
    /bin/bash: error while loading shared libraries: libreadline.so.6: cannot open shared object file: No such file or directory :(
    127 root@archiso ~ #

  • How to sort a 2 dim. array by the first column?

    Hi there,
    I need to know, how to sort a 2 dim. String array by the first column, which means "string[0][x]".
    I think, I have to implement a new comparator class. But how?
    Thanks in advance for any help

    I need to know, how to sort a 2 dim. String
    array by the first column, which means
    "string[0][x]".You want to sort the array using the first element in each row and that element is a String?
    Let's forget about generics. Say you want to supply a Comparator. The compare method should decide the order between elements when passed two element objects. In a two-dimensional array the elements will be one-dimentional arrays and you use the first element in those arrays, like
    public int compare(Object s1, Object s2) {
       String[] a1 = (String[]) s1;  // first row array
       String[] a2 = (String[]) s2;  // second row array
       return a1[0].compareTo(a2[0]); // compare first element of row arrays
    }

Maybe you are looking for

  • Video plays on Root folder but not in Cgi-bin folder...Help!

    Hello- I just transfered my entire website content form one domain to another and for some reson my videos will not play on the new domain whereas they played correctly in the cg-bin folder of the old domain.  I do not understand why and need your he

  • How do I know how many bytes it has read so far ?

    Like in a FileInputStream.read(byte [] b) method. How do I know how many bytes have been read into b so far ? Thanks!

  • Content-Length missing in SOAP request

    In Oracle Application Server, a SOAP request like : POST /eai_esn/start.swe?SWEExtSource=WebService&SWEExtCmd=Execute&WSSoap=1 HTTP/1.1 SOAPAction: "document/http://siebel.com/marketing/import:MktgImportServiceInvokeImportJob" User-Agent: Axis2 Host:

  • Function to create Input Dialog for Search Help

    Hi Folks, Is there any function to create the dialog to limit the search help result as the one that appears when you create the Search Help through the SE11. This is because when I use F4IF_FIELD_VALUE_REQUEST I'm just being able to set one value to

  • Gcin can't switch input

    I've been pondering this problem and hope someone can give me a hint. Ever since I ran pacman update a couple of days ago, it's several months before the last update, I'm unable to toggle to different input. When I login to gnome, gcin icon shows up