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 .

Similar Messages

  • How to create a Double dimension array dynamically

    Hello,
    If I have the following code running...
    String[][] str = new String[1][3];
    str[0]0] = "AAA";
    str[0][1] = "BBB";
    str[0][2] = "CCC";
    I want to do the same code using runtime object creation. i.e.
    String class_name = "java.lang.String";
    How will I write the above mentioned code without using the hard code String class, i.e. I have to use class_name instead of "String".
    Please help me.
    Thanks in advance,
    Anmol

    Thanks Drake,
    I got the solution i.e.
    String class_name = "java.lang.String";
    String ele_type = "java.lang.String";
    int ele_size = 3;
    String s1 = new String("AAA");
    String s2 = new String("BBB");
    String s3 = new String("CCC");
    ArrayList ar = new ArrayList();
    ar.add(s1);
    ar.add(s2);
    ar.add(s3);
    Object base_obj = java.lang.reflect.Array.newInstance(Class.forName(class_name), new int[]{1,ele_size});
    Object child_obj = java.lang.reflect.Array.newInstance(Class.forName(ele_type), ele_size);
    for(int i=0;i<ele_size;i++){
    Array.set(child_obj, i, ar.get(i));     
    Array.set(base_obj,0,child_obj);               
    // base_obj object is same as str shown in the above code
    Thanks,
    Anmol

  • 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

  • Creating a byte Array dynamically.Urgent Help needed.

    Hi there,
    I need to create a byte Array with the values
    derived from the array and then am passing this byte array
    to a method.
    Example :
    public static void main(String[] args) throws IOException {
    char chars[] = {'a','j','a','y'};
    byte[] b = {
    (byte) chars[0],(byte) chars[1],(byte) chars[2],(byte) chars[3],
    //** Send name to a server.
    sendRequest(b);
    This is all right.
    But here I know the size of the character array chars.
    If it had more than 4 characters or less than 4,
    is there a way to create the byte array dynamically based on the values in the character array?
    Please can some one help me with creating a byte array on the fly?
    Has anyone understood my question please?
    A response is much much appreciated.

    The actual problem is this.
    The byte array already has some fixed values to it
    and i need to append the values of the character array
    to this byte array
    ie
    char chars[] = {'a','j','a','y'};
    byte b[] = {
    // Predefined values
    (byte) 0x01, (byte) 0x7E, (byte)0x03
    // I have to add the values from the array here
    (byte) chars[0], (byte) chars[1]....
    How can I add these values.? The size of the character array
    can vary

  • Creating a byte Array dynamically.An Urgent Request.

    Hi there,
    I need to create a byte Array with the values
    derived from the array and then am passing this byte array
    to a method.
    Example :
    public static void main(String[] args) throws IOException {
    char chars[] = {'a','j','a','y'};
    byte[] b = {
    (byte) chars[0],(byte) chars[1],(byte) chars[2],(byte) chars[3],
    //** Send name to a server.
    sendRequest(b);
    This is all right.
    But here I know the size of the character array chars.
    If it had more than 4 characters or less than 4,
    is there a way to create the byte array dynamically based on the values in the character array?
    Please can some one help me with creating a byte array on the fly?
    Has anyone understood my question please?

    Well, if you have the byte array already, you're probably going to have to either make the original array large enough to hold whatever you would put into it or create a new array when you know what you are going to add.
    This seems pretty simple, so maybe I'm missing the point. But...
    char chars[] = { ... };
    byte bytes[] = new byte[<some other size> + chars.length];
    for (int i = 0; i < chars.length; i++)
    bytes[i + <offset>] = (byte)chars;
    If you can't effectively figure out a static size for this array and you have to copy contents, look at System.arrayCopy() to possibly improve performance of the copy.

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

  • 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

  • Creating and Binding View Objects dynamically : Oracle Jdeveloper 11g

    Hello,
    We are trying to create and bind view objects dynamically to adf data visualization components.
    The view object is a result of multiple tables.
    We are using Oracle JDeveloper 11g Technical Preview. ( can't upgrade to TP2 or TP3 now).
    We have found this : http://radio.weblogs.com/0118231/stories/2003/07/15/creatingUpdateableMultientityViewObjectDefinitionsDynamically.html on our search for the same.
    The sample application however, is in 10g , hence required migration.
    Also, it was a standalone application with the TestClient.java having a main() method.
    Our requirement is for Web Application; we use Adf+jsf .
    Guidance of any sort is very much appreciated.
    Thanks in advance.
    -Anil Golla

    Hi,
    there also exist a forum for JDeveloper 11: JDeveloper and OC4J 11g Technology Preview
    What you are trying todo is not trivial because you need to not only dynamically create the VO, you would also dynamically need to create the binding meta data for it (assuming you use ADF). Not sure if the API to modify the binding is public, so posting it on the JDeveloper 11 forum bears a glimpse of hope for an answer
    In JDeveloper 10.1.3 you can't do this
    Frank

  • How can i create a button with a dynamic picture?

    How can i create a button with a dynamic picture using
    mcLoader.loadClip
    I did create one with it doesnt seem to be working. It loses
    all its
    functions (eg onPress onRelease)
    Thanks

    I solved thep roblem anyway creating a mc.. then creating
    another MC withing
    the first MC and i change the picture on the second MC. And i
    apply the
    propierities to the first MC , and works
    If i have troubles with mu sistem on the future I will use
    yours!
    Thanks!
    "the fleece" <[email protected]>
    escribi� en el mensaje
    news:e67i88$jlf$[email protected]..
    > the image loading will remove any properties or
    functions the mc had.
    >
    > you need to apply them in the onLoadInit function
    >
    > mclListener.onLoadInit = function(target_mc:MovieClip) {
    > target_mc.onRollOver=blah blah
    > };
    > var image_mcl:MovieClipLoader = new MovieClipLoader();
    > image_mcl.addListener(mclListener);
    > image_mcl.loadClip(blah, blahblah);
    >
    >

  • How to create and use mutable array of UInt8

    Hello!
    If I get it right, UInt8 *buffer, buffer - is a pointer to a start of array?
    Then how to create and use mutable array of UInt8 pointers?
    The main target is a creation of the module that will store some byte array requests and will send all of them at the propriate moment.

    I try
    - (void) scheduleRequest:(UInt8 *)request {
    if (!scheduledRequests) scheduledRequests = [[NSMutableArray array] retain];
    [scheduledRequests addObject:request];
    But get warning:"passing argument 1 of 'addObject:' from incompatible pointer type"

  • How to create a roadmap ui element dynamically in webdynpro abap?

    Dear  team
    iam new for webdynpro my question is how to create the road map programme dynamically using webdynpro
    could you tell me what are the steps i have to take, what are the elements i have to bind?
    and what code & where i have to write the code?
    regards
    sathya

    Hi Sathya,
                  Write the follwing code in WDDOMODIFYVIEW method to create a Dynamic ROADMAP and also create an attribute of
                   type string to control the selection of steps in road map.
    method WDDOMODIFYVIEW .
      data : lr_ele type ref to if_wd_view_element.
      data : lr_rm type ref to cl_wd_road_map.
      data : lr_step type ref to cl_wd_road_map_step.
      data: lr_container type ref to cl_wd_transparent_container.
      data : lr_flowdata type ref to cl_wd_flow_data.
      CALL METHOD view->get_root_element
        receiving
          root_view_element = lr_ele.
      lr_container ?= lr_ele.
    CALL METHOD cl_wd_road_map=>new_road_map
      EXPORTING
        id                       = 'ROADMAP'
      receiving
        control                  = lr_rm.
    CALL METHOD lr_rm->bind_selected_step
      EXPORTING
        path   = 'VALUE'.
    CALL METHOD cl_wd_flow_data=>new_flow_data
      EXPORTING
        element     = lr_rm
      receiving
        control     = lr_flowdata.
    CALL METHOD lr_container->add_child
      EXPORTING
        index     = 1
        the_child = lr_rm.
    CALL METHOD cl_wd_road_map_step=>new_road_map_step
      EXPORTING
        id                  = 'ONE'
        name                = '1'
      receiving
        control             = lr_step.
    CALL METHOD lr_rm->add_step
      EXPORTING
        index    = 1
        the_step = lr_step.
    CALL METHOD cl_wd_road_map_step=>new_road_map_step
      EXPORTING
        id                  = 'TWO'
        name                = '2'
      receiving
        control             = lr_step.
    CALL METHOD lr_rm->add_step
      EXPORTING
        index    = 2
        the_step = lr_step.
    CALL METHOD cl_wd_road_map_step=>new_road_map_step
      EXPORTING
        id                  = 'THREE'
        name                = '3'
      receiving
        control             = lr_step.
    CALL METHOD lr_rm->add_step
      EXPORTING
        index    = 3
        the_step = lr_step.
    endmethod.
    Then you can use the context attribute to navigate between the steps and do respective actions.

  • How to create a MD form using dynamic page ?

    Rahul and Sharmila,
    You have answered several of my queries earlier and I am thankful for them.
    I have been trying to creating a MD form using dynamic page and I haven't fiqured it out. I need help. You both advised me on creating a simple form using dynamic page. The complexity changes drastically when I have to create a MD form. Has no body ever tried to create a MD form with dynamic page?
    I haven't heard from you anything either. I am stuck with this and I need help urgently. Would you kindly tell me if this is possible and how ? Otherwise, I will stop crying for help on this.
    Thanks for your kind attention.
    Mainak

    Hi,
    I have replied to this in the morning.
    Re: Oracle portal and JSR 168 compliance
    Hope it helps.
    Thanks,
    Sharmila

  • To create a deep structure for dynamic internal table.

    Hello
    My ALV has fields which are defined dynamically during execution.
    so, i did it in the following way,
    Declared Field symbolds, DREF and fieldcatalog as,
    FIELD-SYMBOLS: <t_dyntable> TYPE STANDARD TABLE,
                  <fs_dyntable>.
    DATA:   dref_dyntab    TYPE REF TO data,
            dref_dynwa     TYPE REF TO data.
    DATA: ts_fieldcatalog TYPE lvc_t_fcat.
    DATA: wa_fieldcatalog TYPE lvc_s_fcat.
    Updated Fieldcatalog dynamically as,
    *function module to read segment structure
        CALL FUNCTION 'SEGMENT_READ'
          EXPORTING
            segmenttyp           = v_segment_name
          TABLES
            segmentstructure     = ts_seg_structure
          EXCEPTIONS
            no_authority         = 1
            segment_not_existing = 2
            OTHERS               = 3.
        IF sy-subrc <> 0.
          CASE sy-subrc.
            WHEN '1'.
              MESSAGE e024.
              STOP.
            WHEN '2'.
              MESSAGE e025 WITH v_segment_name.
              STOP.
            WHEN OTHERS.
              MESSAGE e023.
          ENDCASE.
        ENDIF.
    *FETCH FIELDS FROM STRUCTURE OF SEGMENT AND CREATE FIELDCATALOG FOR
    EACH FIELD OF SEGMENT (DYNAMIC FIELD CATALOG)
        LOOP AT ts_seg_structure INTO wa_seg_structure.
          ADD 1 TO v_counter.
          wa_fieldcatalog-fieldname = wa_seg_structure-fieldname.
          wa_fieldcatalog-col_pos   = v_counter.
          wa_fieldcatalog-ref_table = wa_seg_structure-segtyp.
          APPEND wa_fieldcatalog TO ts_fieldcatalog.
          CLEAR wa_fieldcatalog.
        ENDLOOP.
    and generated dynamic internal table using fieldcatalog as,
    *--Method to get the structure of table using fieldcatalog.
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = ts_fieldcatalog
        IMPORTING
    *--Variable of type REF TO DATA.
          ep_table        = dref_dyntab.
      IF sy-subrc <> 0.
        MESSAGE e023.
      ENDIF.
    *--Dynamic internal tables required when show segments selected
      IF p_selseg IS NOT INITIAL.
        ASSIGN dref_dyntab->* TO <t_dyntable>.
    *--Create dynamic work area and assign to FS
      CREATE DATA dref_dynwa LIKE LINE OF <t_dyntable>.
        ASSIGN dref_dynwa->* TO <fs_dyntable>.
    And then i populated this <t_dyntable> which is being passed as data-table to method
    CL_GUI_ALV_GRID => SET_TABLE_FOR_FIRST_DISPLAY
    for ALV grid Display along with above used filedcatalog ts_fieldcatalog.
    Things are fine till here, but now i have the requirement to edit selected rows of the ALV display..
    As you might be aware, we need a field
            TS_STYLEROW  TYPE lvc_t_styl, (i.e, a field of type 'h' and we can say as an internal table inside an internal table or else as a deep structure)
    in the output internal table <t_dyntable> to meet our requirement.
    My issue is about declaring one such field of type 'h' in this dynamically created internal table ''<t_dyntable>".
    I tried in the following way by adding one such field to fieldcatalog :
    *Field for Styling
      ADD 1 TO v_counter.
      wa_fieldcatalog-fieldname   = 'TS_STYLEROW'.
      wa_fieldcatalog-tabname     = 'TS_STYLE'.
      wa_fieldcatalog-col_pos     = v_counter.
      wa_fieldcatalog-no_out      = 'X'.
      wa_fieldcatalog-inttype     = 'h'.      " I even mentioned this
      APPEND wa_fieldcatalog TO ts_fieldcatalog.
      CLEAR  wa_fieldcatalog.
    But this is creating a field of type 'C' in the table <t_dyntable> instead of what i was expecting
    Guyz and respected,
    Please advice me with the solution or ur ideas....
    Note : The overall requirement is create a deep structure for dynamically generated internal table.
    Your help is highly appreciated and unforgettable..!!!!!!!

    hi,
    Dynamic append
    Dynamic internal table
    Dynamic internal table
    dynamic columns in ALV
    Variant for dynamic selection
    thanks

  • How can I create a variable size array?

    How can I create a variable size array?

    ok then how can i create a new vector object?If you don't know that, you need to go back to your text book and study some more. Or read the tutorial on the basics of Java: http://java.sun.com/docs/books/tutorial/java/index.html
    After reading that you can move on to: http://java.sun.com/docs/books/tutorial/collections/index.html
    Anyway, the answer to your question is, of course:
    Vector v = new Vector();(But you should probably use ArrayList instead of Vector.)

Maybe you are looking for

  • Nginx + php-fpm problem

    Hello there. I just setup nginx with mysql and php-fpm to my archlinux install and i need help. i checked all over internet and try every solution, none still work. i have a blank page problem this is working correctly: <?php phpinfo(); ?> short tags

  • How do I download my music onto another computer, when I no longer have the music on another computer, ipod, or any other storage device?

    Just as it says: How can I download music again that I have already bought and downloaded once on another computer? I no longer have the music on another computer (I no longer have the original computer) and the only other place I put the music was m

  • Resource Bundle with JRun4 and JDK 1.6

    Hi Everyone I have been using ResourceBundle with JDK 1.4 since quite a long. Following is the code snippet to show the way it was being used. ResourceBundle.getBundle("com.app.resources.sql\\entry_sql" + Locale.US);This code runs on JRun4 (updater 7

  • TOTAL SPENT ANALYSIS REPORT

    I want to run a report on total spend analysis for a period....how do i go about that

  • Handle event of one report in other

    Dear experts, I have a requirement wherein, if an action is done on the selection screen of one report, the event should be caught in an another report which is running in another session. Say if I click refresh button on selection screen of one repo