Manipulating Arrays

Hi I am having trouble with 2D arrays.
public class cross{
public cross() {
A = new String[3][];
A[0] = new String[3];
A[1] = new String[3];
A[2] = new String[3];
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
A[i][j] = "Empty";
Is there anyway i can define a method which makes it possible for me to change the values of a specific element?

Hi I am having trouble with 2D arrays.
public class cross{
public cross() {
A = new String[3][];
A[0] = new String[3];
A[1] = new String[3];
A[2] = new String[3];
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
A[i][j] = "Empty";
}What I am trying to say is that how do i come up with a method, for e.g. changeCross(int x, int y), where x and y will go into A[x][y] and thus I am able to change the value for that particular element. Remember cross is not an array object. Is my concept of array and classes wrong?

Similar Messages

  • [Solved]Bash:Manipulating arrays of paths? the right way or not?

    Note: Refer to the following posts for better solutions and/or alternatives.
    This is a mock segment of a script I'm writting and I need to know if I'm doing it the correct way or at least in a proper bash way...
    the following works but will it always parse in a sorted manner. I have a set of directories that are named by date in the YYYY-MM-DD (International) format and want to be sure that they will always be treated as directory paths even when special characters "\n,\t,\s ...etc" are encountered in the path. The number of these directories changes and is compared to a set NUM-ber variable and when there are more than the set number the oldest ones are removed which brings a second question. Being dated as YYYY-MM-DD they sort from oldest to newest(lexicographical order) but do they always and is this the right way to deal with elements in an array separated by nulls? Any Comments or suggestions would be appreciated as I'm learning bash for the  time being (perl is next) and gathered this from bits and peices on verious wikis and forums. I basically want know if this a correct approach to the subject of extracting and performing actions on elements of an array that are directory paths.
    #!/bin/bash
    oifs="$IFS"
    IFS=$'\0'
    DIRTREE=(/path/to/dated/directories/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]/)
    NUM=5
    HOWMANYMORE=$(echo $(( ${#DIRTREE[@]} - $NUM )))
    if (( ${#DIRTREE[@]} > $NUM )) ; then
    rm -rv "${DIRTREE[@]:0:$HOWMANYMORE}"
    fi
    IFS="$oifs"
    Note:I have tested this for those wondering
    Last edited by Thme (2012-11-30 16:58:13)

    aesiris wrote:
    there is a special syntax for appending elements to an array:
    array+=(element1 element2 ...)
    you can simplify to
    NUM=3
    combined=()
    for dir in set1 set2 set3; do
    new=(/home/maat/dateddirs/"$dir"/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]/)
    (( count= ${#new[@]} - NUM ))
    combined+=("${new[@]:0:$count}")
    done
    This works as really well, however, in my case I still need the other sets in separate arrays for other purposes in my personal script so I adapted the approach a little and got this which uses the array+=(foo) syntax properly now. I was aware of this feature in bash arrays and experimented with it but had no success adding elements from other arrays until you demonstrated it in your example by adding them though a "for loop" and doing the arithmetic there... My current one now is very similar...I'm not sure how to reduce it further if possible but I need the other arrays as I do something completely different with them:
    #!/bin/bash
    NUM=10
    set1=(/home/maat/datedfolders/set1/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]/)
    set2=(/home/maat/datedfolders/set2/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]/)
    set3=(/home/maat/datedfolders/set3/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]/)
    CT1=$(( ${#set1[@]} - NUM ))
    CT2=$(( ${#set2[@]} - NUM ))
    CT3=$(( ${#set3[@]} - NUM ))
    for X in "${set1[@]:0:$CT1}" "${set2[@]:0:$CT2}" "${set3[@]:0:$CT3}"
    do
    combined+=("$X")
    done
    for
    for Xdirs in "${combined[@]}"
    do
    rm -rv "$Xdirs"
    done
    I'm considering changing the title of this thread as it reveals a little more than I originally expected to go over and provides some pitfalls as well as ways to approach array manipulation which can be applied to wide range of uses in bash scripting. Others may find totally different uses for what we've discussed here so....
    Last edited by Thme (2012-11-30 10:41:02)

  • Manipulation array

    Ok well,
    I`m currently block on one simple problem, But I don`t find the solution......... And sure it is simple....
    It`s easier with one drawing, I want to do this :
    1 1
    2 2
    3 3
    4 4
    5 5
    6 6
    And want to change the array to have :
    1 1 4 4
    2 2 5 5 
    3 3 6 6
    I found this post
    http://forums.ni.com/t5/LabVIEW/array-manipulation/m-p/2871852/highlight/true#M835498
    I don`t have lbview 2012 but one older version, I tried to play with shifts register and build array, but I`m a little lost.
    If someone has the solution, it`s welcoming.
    Solved!
    Go to Solution.

    You can use Insert Into Array in order to combine 2D arrays "next to each other" instead of "on top of each other", allowing you to simply split the array and then recombine:

  • Building and manipulating Arrays within MathScript

    Hi LabVIEW forum,
    Does anyone have any advice, examples or other useful information about how to build and manipulate (i.e. find elements in arrays) from within a MathScript node ?
    Regards,

    Is this related to your other post? If so, you should keep the discussion to the same thread so people have some context to the question.
    If you're asking a general question... have you looked at the documentation?

  • Inorder traversal manipulating array

    I have an array of integers in main that I store into a binary search tree, I want to use my inorder traversal routine to store the values back into the array contained in main.
    Shouldn't I be able to refrence the array in main if I declare it as protected?
    I get an unresolved symbol error in NetBeans when I try this. What is the proper way.
    again Thanks for any help given.

    I have an array of integers in main that I store into
    a binary search tree, I want to use my inorder
    traversal routine to store the values back into the
    array contained in main.Just out of curiosity -- if you store these values back in the array again the way you intend to, you've
    effectively sorted the original array. Why not sort the array in the first place? You don't need that
    search tree at all ...
    kind regards,
    Jos

  • I'm having problems manipulating array data within a for loop, and extracting the required sub-arrays generated.

    Hi,
    I'm using labVIEW V5.1
    I'm trying to generate 10 1D arrays, the first array is initialized to all zeroes, then I have set up a for loop which shifts the first element by 1, then a random number is placed into the first element position. I am using a shift register to feed back in the newly generated array into the start of the loop.
    By the end of the each loop I want to be able to use the array generated in an algorithm outside the loop. However I only want the Nx1 array that has just been generated.
    Unfortunately, I cannot figure out how to resize, reshape or index the output array to do this.
    I would like the loop to
    give me out a 1D array after each iteration.
    Any help would be greatly appreciated.

    I hope I've understood your problem.
    First your vi was lacking of the sub-vi working as shift register, I've replaced it with the rotate function.
    The indexing of your arrays create a 2D array whose rows are your 1D array.To pick only one of them you have to use the index array function and select which one you want.
    To use your temporary data in another part of your application you should use a local variable of array2.
    I did it in a separated while loop That I syncronized with the for loop using occurrence, in this way the while loop runs each time a new value is inserted in array2 (each loop of the for loop structure).
    If you don't need this syncronization just get rid of occurrence functions.
    I place a delay in the for loop to show what happens when running.
    Hope it was helpful.
    Alberto Locatelli
    Attachments:
    array_test_v3.vi ‏35 KB

  • Manipulating array

    Hi,
    Sorry for the non accurate title, but it was difficult to really explain it better.
    I would like to realise this in a for loop :
    I'm so lost when I have to manipulate these arrays !
    Thanks you for help,
    Sébastien

     Register name                                                                                                      type              modbus location
    FAULT
    uint16_t
    300004
    TEMPA
    uint8_t
    None
    TEMPB
    uint8_t
    None
    TEMPA/TEMPB
    uint16_t
    300005
    I'd like to search through an string array and if i find a uint8 variable I'd like to create a new row entry which is TEMPA/TEMPB   MSB,LSB uint16 like above.
    Then continue the search. I have 300 variables in this string array and need to pull out all of the unit8 variables in this fashion and put them into uint16 for modbus registers transmission.
    I dont need to append to the current array, creating a new array from the old one is preffered. 
    I can then search through the final array and link the uint16s with modbus registers if  location != none 
    How can i do this ? Any ideas?
    James

  • Manipulating array of data

    X_Value
    Voltage - Dev1_ai0
    0
    2.47051
    4.55E-05
    2.468536
    9.09E-05
    2.475117
    0.000136
    2.471169
    0.000182
    2.475446
    0.000227
    2.473143
    0.000273
    2.473143
    0.000318
    2.469523
    0.000364
    2.468865
    0.000409
    2.470181
    0.000454
    2.470181
    Hi, i dragged my signal from signal viewer into microsoft excel and i was given the above data (above is only a sample). i need to find a way of converting the x-data from freq to range. i have the formulae to do it - but i have not a clue on where to start. n e help would be great thanks.

    what do u mean a read spreadsheet?. read-only?
    the formulae i have to convert freq to range is
    range = freq*c*dT/(2*dF)
    where:
    c   = 3*10^8
    dT = 0.02
    dF = 66*10^6
    How do u do index enabled?
    do u know how to do for loops in excel?

  • How to manipulate arrays using case statements and boolean conditions?

    In the vi that is attached I am trying to compare two values in two different arrays and delete the value that is equal to zero.  The values of each array are rounded to the closest integer.  Then I attempted to apply the ">0" boolean as the condition for my case statement, but I am getting an error.  Any tips on manipulating arrays with case statements?
    Attachments:
    Patient Movement Monitoring.vi ‏141 KB

    Thank you!!! that was a huge help. I don't think I need the case structures at all.  The next part of the code compares the 4 values in the array. 
    If columns 0 and 1 are both positive -> output 1
    If column 0 is negative and 1 is positive -> output 2
    If columns 0 and 1 are both negative -> output 3
    If column 0 is positive and 1 is negative -> output 4
    (0 is x-axis value, 1 is y-axis value.....outputs are assigning quadrants to the combination)
    Only one of the "AND" booleans will return true for each index.  Is there a way to initialize another array of outputs 1-4 depending on which AND returns true?
    Attachments:
    Patient Movement Monitoring.vi ‏144 KB

  • Why won't all the array elements display?

    Hello,
    I am trying to learn about manipulating arrays.  The example finder includes this one," build array_forum.vi", which shows the two modes, concatenate and append, which I can understand, HOWEVER, I cannot figure out how they built this vi.  For example, I can find the Build Array function, but, I cannot understand how they created the "array of numeric data 1"  "array of numeric data 2"...etc, and I cannot find the functions on the palettes that result in the display "build array concatenate inputs".  Where are these blue functions????
    Where are these functions found on the palette, and how does one construct them like this?
    The other vi shown here, "for loop array_forum.vi" is my attempt to duplicate it, but, it does not show all the elements of the array; instead it displays only ONE element, the last element of the array.  How do I display all the elements of the array I am trying to create using the FOR LOOP?  Am I doing something wrong with the FOR LOOP?
    Thanks,
    dave
    Solved!
    Go to Solution.
    Attachments:
    Build Array_forum.vi ‏12 KB
    for loop array_forum.vi ‏7 KB

    Hello Tim and Nilquist,
    Thanks for your help.  Let me re-state my question.  I have studied the Labview basics, and I understand about REPRESENTATION, data types etc., but, take a look at the attached vi.  In it, I have added an indicator, and the indicator I have added is called ARRAY by default, and it is the shape of a large box.  The original indicators in the original example are small boxes are labelled I-32.  Where did the original indicators come from?  Is my indicator identical to the original ones? I am using LV2011 basic.
    Thanks,
    DAve
    Attachments:
    Build Array_forum_2.vi ‏12 KB

  • How do I display all the elements of an array?

    Hello,
    I am trying to learn about manipulating arrays.  The example finder includes this one," build array_forum.vi", which shows the two modes, concatenate and append, which I can understand, HOWEVER, I cannot figure out how they built this vi.  For example, I can find the Build Array function, but, I cannot understand how they created the "array of numeric data 1"  "array of numeric data 2"...etc, and I cannot find the functions on the palettes that result in the display "build array concatenate inputs".  Where are these blue functions????
    Where are these functions found on the palette, and how does one construct them like this? 
    The other vi shown here, "for loop array_forum.vi" is my attempt to duplicate it, but, it does not show all the elements of the array; instead it displays only ONE element, the last element of the array.  How do I display all the elements of the array I am trying to create using the FOR LOOP?
    Thanks,
    dave
    Solved!
    Go to Solution.
    Attachments:
    for loop array_forum.vi ‏7 KB
    Build Array_forum.vi ‏12 KB

    I think I posted this in the wrong place.  I reposted this to the Labview forum.
    Dave

  • Using a loop back node to build array okay instead of shift registers?

    Attached is a sample of how I want to accomplish appending to multiple arrays and would like an opinion wether it is acceptable or not.  I didn't want to use 12 shift registers wired from the 6 possible case structures mainly because of esthetic reasons.  Each case will be called in turn during program execution only once.  So case 0 builds it's array then later case 1 and so on.  It seems to work but frankly manipulating arrays in LV confuses me a bit.  I cannot test in the actual program since the hardware the complete program controls is not yet installed.  Your input as to the wisdom of doing this or proposing a better solution (maybe one that actually works) is appreciated
    Mike
    Attachments:
    sample2.vi ‏33 KB

    You never have more than one element in each array since you initialize the shift register with every call of the VI.
    Use "built array" instead of "insert into array", it's cleaner. However, since you only kep one elements, maybe you can jist place the scalar value inside a shift register. Make sure the default value is NaN so you know when it contains valid data.
    All you probably need is an array of fixed size (12) and replace appropriate elements as need arises.
    What you probably want is an action engine. See http://forums.ni.com/ni/board/message?board.id=170&view=by_date_ascending&message.id=240328#M240328
    LabVIEW Champion . Do more with less code and in less time .

  • Loops in method are never executed??

    Hello,
    I have a short program that I wrote to practice manipulating arrays and to
    practice modular design. The source compiles and the program executes,
    however the 2 loops in the process() method are never entered, I have tried
    do-while loops and the for loop(which was effective for the same program
    written with non-modular design). the program will execute the
    System.out.println("\nThe array values recieved are:\n");
    inside of the process(), but ignores the 2 for loops. I have purposely declared int size; without a value such as int size=0, because I am prompting the user to enter a value for the array and I pass that value into the size of the array.
    I have worked and researched for a couple of days on this. I will post the
    code below and any help would be greatly appreciated. Thanks, Jeff
    import java.io.PrintStream;
    import javabook2.*;
    public class Tester
    public static void main (String [] args)
    {  App a;
    a = new App();
    a.start();
    class App//data members of the App class
    SimpleInput input;
    String tittle;
    int size;
    double [] rainfall;
    public App()
    { //constructor
    input = new SimpleInput();
    rainfall = new double[size];
    public void start()//start method
    describe();
    process();
    public void describe()//prompts the user for info
    tittle = SimpleInput.getString("What is your name?\n");
    System.out.println("\nNice to meet you " + tittle);
    System.out.println("\nWe are now going to get some practice with arrays!");
    size = SimpleInput.getInteger("\nPlease enter the size of your array:");
    System.out.println("\nThe size array you specified is " + size);
    System.out.println("You will be prompted " + size +" times for rainfall values.");
    public void process() // array method, declared in the start() method
    for( int i =0; i<rainfall.length; i++)
    rainfall[i] = SimpleInput.getDouble("\nPlease enter rainfall amount " +(i + 1));
    System.out.println("\nThe array values recieved are:\n");
    for( int i=0; i<rainfall.length; i++)//.length is used if you dont know the size of aray
    System.out.println(rainfall );

    Add rainfall = new double[size]; as the first
    statement in your process method.Thank you all for your responses. I tried adding the above statement as the first line in the process() method and the program worked perfectly. I learned that I tried to construct the array before I even got the value from the user, and that after I got the value is when I should have just passed that value into the array size. thanks, Jeff

  • Long.toString(long, int) throws ArrayIndexOutOfBoundsException

    We're using Long.toString(long, int) to convert a long into a base-32 string, which is used as a primary key for entities in our database. On occasion, Long.toString(long, int) throws an ArrayOutOfBoundsException! This only occurs in the deployed system, I cannot get it to occur in a testing environment.
    The object that contains the call to Long.toString(int, long) is shared by multiple threads, but the state of the object is immutable and access to the object is not synchronized. I have tested this code extensively with multithreaded access and cannot reproduce the exception in a test environment.
    Furthermore, this bug only occurs on Linux.
    As a workaround, we have a loop that will attempt the call 5 times, and then fail if the call could not be completed. Generally, this helps to get the code running but will sometimes fail.
    Here are some characteristics of the problem:
    1) Linux kernel 2.4.10 on Pentium III.
    2) Sun JVM 1.3.1_01
    3) Code is accessed from a session bean deployed into JBoss 2.4.3.
    4) Database entities have undergone bytecode enhancement per JDO specification.
    Obviously, the bytecode enhancement is most suspect here. The class that contains the error-prone code is not enhanced, but entities do contain references to instances of the primary key class.
    At first blush this sounds like a classic memory corruption issue that is surfacing in Long.toString() but is probably caused elsewhere. Has anybody seen anything like this or know of either a solution or suggested debugging procedure?
    Thanks.
    -brian

    We already discussed that approach. The reason that
    it was rejected is because my C experience suggests
    that it will just move the corruption evidence to another
    area of the application with possibly more insidious
    effects.I'm not so sure about that. Does your five-try loop actually help? If a stateless method throws an IndexOutOfBoundsException with a given set of parameters, then I would expect it to always throw this exception with the same parameters. Any other behaviour is non-deterministic and not suitable (IMHO) for a production machine.
    I assume you are manipulating arrays in other locations of your code... if these other locations aren't displaying similar non-deterministic behaviour, then common sense dictates that writing your own toString method will not exhibit the same non-deterministic behaviour.
    A little test, compile a class (TestLong, for argument sake) with the method exactly from the Sun source. Decompile it to byte-code with 'javap -c TestLong', and compare that to the same method from Long with 'javap -c java.lang.Long'. If the bytecode isn't identical (Barring numbering differences for class reference table differences), then the implementation you have is not the expected.
    A final suggestion, try a different JVM - both IBM and Sun provide JVMs for linux?

  • How can I take an asymmetric wave and measure peak distribution?

    Using a profilometer the surface topology of a deposited material can be measured. I want to design a program to read in the raw data files of these profiles and then perform some analysis which will extract the distribution in peak/trough heights and in the distances between peaks. Reading in data, manipulating arrays and producing output files/plots I'm fine with but the problem I'm having is as to what analytical tools can be used on such asymmetric waveforms. I was thinking some form of signal processing technique but I'm not sure. I've attached an example profile for one of my samples to give an idea of what I'm working with...
    Solved!
    Go to Solution.
    Attachments:
    S22b.txt ‏149 KB

    camerond wrote:
    If this is fairly representative of your data, I'd first take a stab at it using the LabVIEW Peak Detector VI (Signal Processing -> Signal Operation). There's not much noise at all compared to the size of your peaks (if we're just talking about the visible ones here), so you might just smooth your data with a Savitsky-Golay function (or such) to take out the little random noise jiggles, offset all your points to make them positive, set a reasonable threshold value and peak width and go to it.
    Now, if you have one huge trough like in the file you sent, you might miss a lot of peaks (again, I don't know what your criteria for a "peak" are). If that happens, I'd suggest looking at the data upside down to find your valleys as inverted "peaks". At this point, you could go back to right-side up, connect the valleys with lines and subtract these points from your data for a pseudo-baseline and run the Peak Detector VI again (you can probably go much more sensitive with your threshold setting because you have taken out most of the very long-term drift). You should have now identified all of your peak and valley points on the X axis. Return to the original data to determine peak heights with whatever baseline algorithm you want to use (linear between valleys, Bezier curves, etc.).
    That's how I'd attack it generically. But this is a very common situation in probably all sciences and engineering fields. Isn't there some standard geological data-crunching method with generally agreed-upon criteria for your problem?
    Cameron
    Thanks for this help; I've used a smoothing filter followed by two peak detectors (one for valleys and one for peaks) and then return the results with good matches to all peaks/valleys, irrelavent of their size. There is still a few "false" peaks that get found, due to residual noise after smoothing, which I'm having to remove manually from the results but even so this has improved my efficiency. Quite simple but I'm new to signal processing!
    I attach my VI for anyone who's interested...
    Attachments:
    DekTakProfileProcessor.vi ‏70 KB

Maybe you are looking for