Weeding out array elements

public class phArray
    public static void main(String[] args)
        double[] phArray = {5.6, 6.2, 6.0, 5.5, 5.7, 6.1, 7.4, 5.5, 5.5, 6.3, 6.4, 2.1, 6.9};
}now, I want to use an "if" statement to find the highest and lowest numbers in the array. My question is; how? I mean, If i wanted to do it with just THIS array, I would obviously just find the element and tell it to print...but I want this to work with multiple arrays.
Any advice?

singramsan89 wrote:
CaptainMorgan08 wrote:
Do you know how to use a for loop to loop through an array?A for loop to loop through Arrays? No.You can do so like this.
for(int i=0; i<phArray.length; i++)
   System.out.println(phArray);
}Once you understand that, the rest should be easy.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • How do I programmat​ically modify array element sizes?

    Hi All,
    I have a quick question about modifying the size of array elements. Hopefully someone can help, because I am at a dead end!
    I am logging some intensities from a Fibre Array using a camera. For calibration of the system, I acquire an image from the camera, click points on the image to divide it into areas of interest. I overlay my image with a grid showing the regions of interst - for example a 4x6 array. I then have to select the fibres - or ROIs - I want to log from.
    I have a cluster type-def ( a number and a boolean) to specify the fibre number and to turn logging from that fibre on/off. I overlay an (transparent) array of this typedef over my image to correspond with the regions of interest. So here's my problem - I want to modify the dimensions of the array so each control matches my ROI. I can resize the elements by rightclicking on the elements on the frontpanel, but can't find a way to do it programmatically. The Array Property Node>>Array Element>>Bounds won't 'change to write'...thats the first thing I tried.
    Its really only important that the elements align with my ROIs - so programmatically adding in gaps/spacings would also work for me...but again I can't figure out how to do this! I've attached a screenshot of part of my image with array overlaid to show you all exactly what my problem is.
    Thanks in advance for you help,
    Dave
    PS I am running Labview 8.6 without the vision add on.
    Solved!
    Go to Solution.
    Attachments:
    Array_Overlay.png ‏419 KB

    Here's my cheat (and cheap?) way If you want to get fancy and center the numeric and boolean indicators, you could add spacers on the north and west sides, too.
    Attachments:
    ClusterSpacer.vi ‏13 KB

  • How to set the value of an array element (not the complete array) by using a reference?

    My situation is that I have an array of clusters on the front panel. Each element is used for a particular test setup, so if the array size is three, it means we have three identical test setups that can be used. The cluster contains two string controls and a button: 'device ID' string, 'start' button and 'status' string.
    In order to keep the diagrams simple, I would like to use a reference to the array as input into a subvi. This subvi will then modify a particular element in the array (i.e. set the 'status' string).
    The first problem I encounter is that I can not select an array element to write to by using the reference. I have tried setting the 'Selection s
    tart[]' and 'Selection size[]' properties and then querying the 'Array element' to get the proper element.
    If I do this, the VI always seems to write to the element which the user has selected (i.e. the element that contains the cursor) instead of the one I am trying to select. I also have not found any other possible use for the 'Selection' properties, so I wonder if I am doing something wrong.
    Of course I can use the 'value' property to get all elements, and then use the replace array element with an index value, but this defeats the purpose of leaving all other elements untouched.
    I had hoped to use this method specifically to avoid overwriting other array elements (such as happens with the replace array element) because the user might be modifying the second array element while I want to modify the first.
    My current solution is to split the array into two arrays: one control and one indicator (I guess that's really how it should be done ;-) but I'd still like to know ho
    w to change a single element in an array without affecting the others by using a reference in case I can use it elsewhere.

    > My situation is that I have an array of clusters on the front panel.
    > Each element is used for a particular test setup, so if the array size
    > is three, it means we have three identical test setups that can be
    > used. The cluster contains two string controls and a button: 'device
    > ID' string, 'start' button and 'status' string.
    >
    > In order to keep the diagrams simple, I would like to use a reference
    > to the array as input into a subvi. This subvi will then modify a
    > particular element in the array (i.e. set the 'status' string).
    >
    It isn't possible to get a reference to a particular element within an
    array. There is only one reference to the one control that represents
    all elements in the array.
    While it may seem better to use references to update
    an element within
    an array, it shouldn't really be necessary, and it can also lead to
    race conditions. If you write to an element that has the
    possibility of the user changing, whether you write with a local, a
    reference, or any other means, there is a race condition between the
    diagram and the user. LV will help with this to a certain extent,
    especially for controls that take awhile to edit like ones that use
    the keyboard. In these cases, if the user has already started entering
    text, it will not be overwritten by the new value unless the key focus
    is taken away from the control first. It is similar when moving a slider
    or other value changes using the mouse. LV will write to the other values,
    but will not rip the slider out of the user's hand.
    To completely avoid race conditions, you can split the array into user
    fields and indicators that are located underneath them. Or, if some
    controls act as both, you can do like Excel. You don't directly type
    into the cell. You choose w
    hich cell to edit, but you modify another
    location. When the edit is completed, it is incorporated into the
    display so that it is never lost.
    Greg McKaskle

  • Problem in assigning value to an array element

    hi all
    in the following prog i am not able to assign the value to the array element
    i am not getting why it is giving me error
    //my program is as follows
    public class ArrayTest
         static int [] intArray = new int[5];
         static int [] intArray1 = new int[1];
         intArray1[0] = 5; // this line gives error
         static char [] charArray = new char[5];
         public static void main(String args[])
              System.out.println(charArray);
              intArray1 = intArray;
    }thanx in advance as usual

    The problem is that you try to execute code outside a method. This can be only done in form of a variable declaration or as a static initilization block which will be executed once when the class is loaded:public class ArrayTest
         static int [] intArray = new int[5];
         static int [] intArray1 = new int[1];
         static char [] charArray = new char[5];
         static {
              intArray[0] = 5;
         public static void main(String args[])
              System.out.println(charArray);
              intArray1 = intArray;
    }

  • Read part of an array element

    Hello All.
    As indicated in the title, I am trying to read part of an array element.
    What I'm doing is reading values from a LeCroy scope using a "write" than "read" I have returned the read values into an array but the issue is the scope returns a value "1, 52.33E-3"
    I simply want the element to be 52.33 that way I can use that for other calculations.
    For example my array is.
    "1, 34.334E-3"
    "1, 53.343E-3"
    "1, 143.232E-"
    And I want it to be
    34.334
    53.343
    143.232
    Thanks!
    Solved!
    Go to Solution.

    Another option is to use Spreadsheet String to Array and use the comma as the delimiter.  It can actually change your string into an array of numbers.  Then you just index out the number you want.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • A basic question/problem with array element as undefined

    Hello everybody,
    thank you for looking at my problem. I'm very new to scripting and javaScript and I've encountered a strange problem. I'm always trying to solve all my problem myself, with documentation (it help to learn) or in the last instance with help of google. But in this case I am stuck. I'm sure its something very simple and elementary.
    Here I have a code which simply loads a text file (txt), loads the content of the file in to a "var content". This text file contents a font family name, each name on a separate line, like:
    Albertus
    Antenna
    Antique
    Arial
    Arimo
    Avant
    Barber1
    Barber2
    Barber3
    Barber4
    Birch
    Blackoak ...etc
    Now, I loop trough the content variable, extract each letter and add it to the "fontList[i]" array. If the character is a line break the fontList[i] array adds another element (i = i + 1); That's how I separate every single name into its own array element;
    The problem which I am having is, when I loop trough the fontList array and $.writeln(fontList[i]) the result in the console is:
    undefinedAlbertus
    undefinedAntenna
    undefinedAntique
    undefinedArial ...etc.
    I seriously don't get it, where the undefined is coming from? As far as I have tested each digit being added into the array element, I can't see anything out of ordinary.
    Here is my code:
    #target illustrator
    var doc = app.documents.add();
    //open file
    var myFile = new File ("c:/ScriptFiles/installedFonts-Families.txt");
    var openFile = myFile.open("r");
    //check if open
    if(openFile == true){
        $.writeln("The file has loaded")}
    else {$.writeln("The file did not load, check the name or the path");}
    //load the file content into a variable
    var content = myFile.read();
    myFile.close();
    var ch;
    var x = 0;
    var fontList = [];
    for (var i = 0; i < content.length; i++) {
        ch = content.charAt (i);
            if((ch) !== (String.fromCharCode(10))) {
                fontList[x] += ch;
            else {
                x ++;
    for ( i = 0; i < fontList.length; i++) {
       $.writeln(fontList[i]);
    doc.close (SaveOptions.DONOTSAVECHANGES);
    Thank you for any help or explanation. If you have any advice on how to improve my practices or any hint, please feel free to say. Thank you

    CarlosCantos wrote an amazing script a while back (2013) that may help you in your endeavor. Below is his code, I had nothing to do with this other then give him praise and I hope it doesn't offend him since it was pasted on the forums here.
    This has helped me do something similar to what your doing.
    Thanks again CarlosCanto
    // script.name = fontList.jsx;
    // script.description = creates a document and makes a list of all fonts seen by Illustrator;
    // script.requirements = none; // runs on CS4 and newer;
    // script.parent = CarlosCanto // 02/17/2013;
    // script.elegant = false;
    #target illustrator
    var edgeSpacing = 10;
    var columnSpacing = 195;
    var docPreset = new DocumentPreset;
    docPreset.width = 800;
    docPreset.height = 600;
    var idoc = documents.addDocument(DocumentColorSpace.CMYK, docPreset);
    var x = edgeSpacing;
    var yyy = (idoc.height - edgeSpacing);
    var fontCount = textFonts.length;
    var col = 1;
    var ABcount = 1;
    for(var i=0; i<fontCount; i++) {
        sFontName = textFonts[i].name;
        var itext = idoc.textFrames.add();
        itext.textRange.characterAttributes.size = 12;
        itext.contents = sFontName;
        //$.writeln(yyy);
        itext.top = yyy;
        itext.left = x;
        itext.textRange.characterAttributes.textFont = textFonts.getByName(textFonts[i].name);
        // check wether the text frame will go off the bottom edge of the document
        if( (yyy-=(itext.height)) <= 20 ) {
            yyy = (idoc.height - edgeSpacing);
            x += columnSpacing;
            col++;
            if (col>4) {
                var ab = idoc.artboards[ABcount-1].artboardRect;
                var abtop = ab[1];
                var ableft = ab[0];
                var abright = ab[2];
                var abbottom = ab[3];
                var ntop = abtop;
                var nleft = abright+edgeSpacing;
                var nbottom = abbottom;
                var nright = abright-ableft+nleft;
                var abRect = [nleft, ntop, nright, nbottom];
                var newAb = idoc.artboards.add(abRect);
                x = nleft+edgeSpacing;
                ABcount++;
                col=1;
        //else yyy-=(itext.height);

  • Best way to iniitialize a queue with array elements

    Hi Guys
    I'm looking for a bit of performance optimization..  
    I'm developing a noise measurement application using LV8.6 and Win Xp /Win 7.
    To put it very simple I have a loop that samples, and a loop that does the math. data is shipped in a queue, producer / consumer style.
    So far so good.. Question is - is there a specific and more optimized way to declare this queue?
    I was wondering if declaring the queue with an initialized array element of a fixed size (the number of samples pr. read from the sound card will be known at runtime) would produce a queue that would be less heavy on dynamic allocation of memory compared to a queue obtained using a simple control no values.
    I've attached a screen dump to maybe make the question more obvious..
    I've been thru the "clear as mud" thread, as recommended in other threads that covers this topic - but i gets very high tech, and I kind of lost my way in it.. So looking for a more simple "you should use solution #x, because..."
    Thank you in advance. 
    Solved!
    Go to Solution.

    I believe (but am not sure) RT FIFOs will allocate this memory for you ahead of time. But, remember they are not deterministic on windows. You need to wire an array constant of the correct size into the FIFO read function also to avoid memory allocation, which is easy to overlook. It's worth looking into, if nothing else, assuming you have RT functions available. WIth this method, the queue size needs to be set, and you run the risk of overflowing and losing elements if not handled correctly. 
    Just throwing other options out there.
    CLA, LabVIEW Versions 2010-2013

  • Out XML element values extract

    hi their
    How can I out XML element the values extract and in a loop in variable and/or in an array store?
    Example:
    [loop]
    <SA>'MS','GYM'</SA>
    Values 'MS' and 'GYM' should be in variables e.g var1='MS' and var2='GYM'
    [end loop]
    Please, help me!!!! Urgent
    thanx you for advice
    kind regards
    Holger

    create or replace procedure spTestXML is
      xml   xmltype;
      test  varchar2(100);
      test2 xmltype;
      cursor lvCur_GetAllSecGrps is
        SELECT extractValue(value(asec), '/SEC_GRP/NAME') as Name
        FROM table(xmlsequence(xml)) a,
             table(xmlsequence(extract(value(a), '/EVENT/SEC_GRP_LIST/SEC_GRP'))) asec;
    begin
      xml := xmltype('<EVENT>
    <SWTSUPDATE TYPE="1">
    <MEMBERID>9822598</MEMBERID>
    <DATETIME>Fri Jun 09 14:51:33 CDT 2006</DATETIME>
    <USERID>W951FVK</USERID>
    </SWTSUPDATE>
    <CONTACT_HISTORY>
    <USER>
    <USER_ID>W951FVK</USER_ID>
    <FIRST_NAME>John</FIRST_NAME>
    <LAST_NAME>Givens</LAST_NAME>
    </USER>
    <USER>
    <USER_ID>W951FNN</USER_ID>
    <FIRST_NAME>Mary</FIRST_NAME>
    <LAST_NAME>McNair</LAST_NAME>
    </USER>
    <CONSUMER>
    <CONS_SEQ_NBR>1387445</CONS_SEQ_NBR>
    <FIRST_NAME>SPRINGHOUSE</FIRST_NAME>
    <LAST_NAME>ELLIS</LAST_NAME>
    </CONSUMER>
    </CONTACT_HISTORY>
    <SEC_GRP_LIST>
    <SEC_GRP><NAME>cspupdatecustpayee</NAME><DESCRIPTION>Add/Update/Delete CSP Customer Payees</DESCRIPTION></SEC_GRP>
    <SEC_GRP><NAME>cspupdatepayment</NAME><DESCRIPTION>Add/Update/Delete CSP Payment</DESCRIPTION></SEC_GRP>
    <SEC_GRP><NAME>adminreports</NAME><DESCRIPTION>Administrate Reports</DESCRIPTION></SEC_GRP>
    <SEC_GRP><NAME>billopscsr</NAME><DESCRIPTION>Bill Operations CSR</DESCRIPTION></SEC_GRP>
    </SEC_GRP_LIST>
    </EVENT>');
      if xml.existsNode('/EVENT/SEC_GRP_LIST/SEC_GRP/NAME') != 0 THEN
        for lvAllSecGrps in lvCur_GetAllSecGrps loop
          dbms_output.put_line('Found: '||lvAllSecGrps.Name);
        end loop;
      end if;
    end spTestXML;gives
    Found: cspupdatecustpayee
    Found: cspupdatepayment
    Found: adminreports
    Found: billopscsrhth

  • Array Element.Disabled

    I have an existing VI where the original programmer has a 2D array of booleans.
    He sets the Array Disabled property to Disabled and Grayed Out.
    He is also setting the Array Element.Disabled property to Disabled and Grayed Out.
    I am not understanding why it is also necessary to do the latter.

    Yeah, my quick test shows there is no point in also setting the disabled property of the control in the array.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Chart array elements separately

    Labview forum,
    I have a for loop which produces an array of 2 elements.
    This is contained within an outer loop.  Inside the outer loop, I have connected the array to a chart function.  For each outer loop iteration, the the chart plots both array elements as sequential elements in the same plot.  This was not the behaviour I wanted.
    Instead, with each outer loop increment, I would like each array element to be added to a separate curve on the same chart axes.  Thus, in this case, two curves would be plotted simultaneously.
    How can I achieve this?
    Attached is a simple example of my current situation.
    Regards,
    Jamie
    Message Edited by Jamieg on 09-17-2007 06:45 AM
    Using Labview version 8.0
    Attachments:
    sample chart loop.vi ‏14 KB
    sample chart loop1.vi ‏14 KB

    An alternative solution uses the "array to cluster" function. (Don't forget to set the cluster size!)
    Message Edited by altenbach on 09-17-2007 07:50 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    sample_chart_loop1MOD.vi ‏15 KB
    multichart.png ‏2 KB

  • Combining two StringBuffer array elements into a single array element

    I just need to know how to combine two stringBuffer array elements into one
    StringBuffer ciphertext [] = new StringBuffer[2];
              StringBuffer s0 = new StringBuffer("11011111111110001001101110110101");
              StringBuffer s1 = new StringBuffer("00010011001101000101011101111001");
              ciphertext[0] = s0;
              ciphertext[1] = s1;
              ciphertext[2] = ciphertext[0].append(ciphertext[1]);I get an array index out of bounds exception:2
    Thanks

    StringBuffer ciphertext [] = new StringBuffer[3];  // legal index values are: 0,1,2

  • Sum array elements not working

    I am trying to output the average % standard deviation per point for a series of data sets.  To do this I want to use the sum array elements function.  The program I have written should work I am pretty sure, but when I watch data flow through it, 1000 points get input into the sum function and NaN comes out.  What could cause an error like this?  I have tried inverting my array, etc.  Is there a limit to the number of points the function can take?  Or to the precision of the points being input?  Thanks, this is driving me crazy! 
    [I renamed the file and attached it again so you can open it - Molly K]
    Message Edited by Support on 07-06-2005 08:23 AM
    Attachments:
    Average % Std Dev.vi ‏23 KB
    Average.vi ‏23 KB

    Any arithmetic operation on a NaN value is invalid and must result in NaN as
    well. You probably need to make sure first that your array doesn't
    contain NaN, Inf, and -Inf.
    Rolf Kalbermatter
    Message Edited by rolfk on 07-05-2005 11:37 AM
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Trying to use .split with an array element

    I have tried multiple ways to split an array element into its components that are separated with a space with this code:
    public static void compareHand(String[] hand){
            for (int i = 0; i < hand.length; i++){
                System.out.println(i);
                System.out.println(hand);
    String[] tokens = hand[i].split("\\s");
    System.out.println(tokens.length);
    for (int j = 0; j < tokens.length; j++){
    System.out.println(tokens);
    I keep getting strange output like the following:
    King of Spades
    3
    [Ljava.lang.String;@10b62c9
    [Ljava.lang.String;@10b62c9
    [Ljava.lang.String;@10b62c9
    where I am expecting:
    King of Spades
    3
    King
    of
    Spades
    Any ideas where I am going wrong?

    public static void compareHand(String[] hand){
             for (int i = 0; i < hand.length; i++){
                  System.out.println(i);
                  System.out.println(hand);
    String[] tokens = hand[i].split("\\s");
    System.out.println(tokens.length);
    for (int j = 0; j < tokens.length; j++){
    System.out.println(tokens); // your error is on this line. Hint ... System.out.println(tokens[...]);

  • Accessing a user array elements in Captivate 6

    Hi guys I have a piece of code that's not working I was hoping someone had any clue as to why, I've wasted too many hours trying to figure this out.  Here's the code, explanation below.
    var objCP = document.Captivate;
    objCP.cpEISetValue("m_VarHandle.questionList", new Array(7));
    objCP.cpEISetValue("m_VarHandle.questionList[0]", 1);
    objCP.cpEISetValue("m_VarHandle.questionList[1]", 2);
    objCP.cpEISetValue("m_VarHandle.questionList[2]", 1);
    objCP.cpEISetValue("m_VarHandle.questionList[3]", 2);
    objCP.cpEISetValue("m_VarHandle.questionList[4]", 1);
    objCP.cpEISetValue("m_VarHandle.questionList[5]", 2);
    var cat1Len = 0;
    var cat2Len = 0;
    for (var i=0;i<objCP.cpEIGetValue("m_VarHandle.questionList.length");i++){
    var value = objCP.cpEIGetValue("m_VarHandle.questionList[i]");
    if (value == 1)
       {cat1Len++;}
    if (value) == 2)
       {cat2Len++;}
    alert(i);
    alert(objCP.cpEIGetValue("m_VarHandle.questionList[2]"));
    alert(value);
    I'm attempting to create a list using a captivate variable I've created called "questionList".
    I fill questionList with data and and then use that data to count, in this instance with cat1Len and cat2Len.
    After that I attempt to verify that the data is being returned correctly with a series of alerts.
    Here's the problem:
    alert(i) correctly reports the number my incrementer should be at.
    alert(objCP.cpEIGetValue("m_VarHandle.questionList[2]")) correctly reports the data in cell [2] of questionList
    but...
    alert(value) reports undefined.  How can this be? I know that I can access array elements from inside this loop and I know that I my incrementer is at the correct location so what's the deal?
    Thanks for any help!

    should be:
    var objCP = document.Captivate;
    objCP.cpEISetValue("m_VarHandle.questionList", new Array(7));
    objCP.cpEISetValue("m_VarHandle.questionList[0]", 1);
    objCP.cpEISetValue("m_VarHandle.questionList[1]", 2);
    objCP.cpEISetValue("m_VarHandle.questionList[2]", 1);
    objCP.cpEISetValue("m_VarHandle.questionList[3]", 2);
    objCP.cpEISetValue("m_VarHandle.questionList[4]", 1);
    objCP.cpEISetValue("m_VarHandle.questionList[5]", 2);
    var cat1Len = 0;
    var cat2Len = 0;
    for (var i=0;i<objCP.cpEIGetValue("m_VarHandle.questionList.length");i++){
    var value = objCP.cpEIGetValue("m_VarHandle.questionList["+i+"]");
    if (value == 1)
       {cat1Len++;}
    if (value) == 2)
       {cat2Len++;}
    alert(i);
    alert(objCP.cpEIGetValue("m_VarHandle.questionList[2]"));
    alert(value);
    i is only defined local to the javascript eval, not a global variable.  You have to pass the value, not the name of the index...
    (I just realized that this question was from 2012, but maybe it might still benefit someone...  I saw it while I was looking for something else)

  • Coordinates of array elements

    Hi,
    I'm playing around with mouse click coordinates, mostly because its Friday afternoon but also because it might be useful
    In the attached code I wish to click on one of the strings of my array control and find out which element in the array it corresponds to. (This will later be used to fire up other bits of code depending on the array content)
    I can use the position of the array and the coordinates of the mouse and it all works fine.
    BUT... only if I select the zeroth element before I run the code. If I select any other element then run the code I get erroneous results.
    So - is there a way to acquire the coordinates of the zeroth element of my array regardless of what the user has just done?
    I can think of workarounds using the coordinates of the array control (instead of the string coordinates) but this is affected by the control label size/visibility so feels less reliable.
    Using version 8.5.
    Thanks,
    Ian
    Solved!
    Go to Solution.
    Attachments:
    click on array.vi ‏23 KB

    There is a utility VI from the LAVA repository located here.
    That deals with this problem:
    Ton
    Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
    Nederlandse LabVIEW user groep www.lvug.nl
    My LabVIEW Ideas
    LabVIEW, programming like it should be!

Maybe you are looking for

  • Spoo Id not geting created while submitting a program at the background

    Hi All, I am submitting a Z program from other Zprogram.  I am actually creating a JOB and submitting the Z program.  Please find the code below, LOOP AT pernr.   CLEAR p_job.   p_stim = p_stim + 120.   CONCATENATE'ITSlip' pernr-low p_job sy-datum IN

  • A good solution to set the actual data record after execute query ..

    Hi, in my Form there is a block on a temporary table. The user can add query results and wishes to save the last data focus on the last actual record before the execute query to restore this focus after the query. Is there a robust and fast solution

  • Problems publishing to godaddy

    Using cyberduck. Everything's getting there, just fine. Problem is my page doesn't show up. Tech support says it's a conflict between my index page and a page I have labeled "home" (which is just like the index page, but I wanted it named home not "i

  • Dvd not playing

    when insert a dvd into the drive, it plays fine, but the video does not show up. The audio is good, just no video. Any ideas??

  • Set Timestamp in a textfield

    Hello I have a PDF form in which I would like to capture the time user has started on an application. I would like to capture the date and time stamp when the user starts entering in a field. I would like to capture the date and time on the 'Change'