Modifying string arrays

Hello experts,
  I'm a labview newbie, but I haven't found anything that's quite like this in the knowledge base: Below is a simplified version of a data collection vi I built.
The vi in the screenshot uses a random number generator, but my real vi polls data from a magnetic susceptibility meter. The for loop iterates for however many times are needed for my test, which is dictated by the length of the sample I am measuring and the desired resolution, which is set before the test sequence begins. In the real vi, the for loop builds the array into a table (string format) in real time, so that the values can be seen in the front panel while it runs. The real vi converts decimals to string format in engineering notation, for the table to display. Now here's what I'm after:
If "apply" is selected, I want to be able to apply a linear correction to one of the columns in my table and spit out a new column. This has to be done after all of the measurements have already been made. The reason for this is that my sensor requires a "drift correction", wherein a blank measurement is made at the end of the sample, and all the values in between are adjusted linearly at each increment to make up for drift as the coil warms up during use. This is sort of like making sure a scale reads zero after something has been weighed, just to make sure the scale was working right, and then adjusting the measurement after the fact.
My question is, what would I put inside the case structure to accomplish this? In the simplified version depicted, I want to pass the array out of the shift register and into the next frame of my flat sequence. From there, I have already learned how to use the "index array" function to extract a column, and the "Replace array subset" function, to inject a new column into my old array (in the picture, I'll just be using a new table to show the modified data). I ran into trouble when I tried to apply mathematical functions to the elements, which are already in string format for the table. I tried using the "decimal string to number" function to bring the string data into numerical format so that I could say, multiply it by two. The problem there was that the function stops converting when it hits a decimal point, and all of my values are extremely small, between 0 and 1. Can anyone think of any way to take the string data and apply arithmetical operators to them, and then replace the subset of my original array with the new column?
Thank you for your insight!
Solved!
Go to Solution.
Attachments:
augment array.jpg ‏223 KB

You are initially dealing with numerics, right?  Why do you convert everything to string before doing the linear correction?  Keep everything numeric until you need to display it.  You don't even need a loop to do so.  Most functions in LabVIEW are polymorphic and are more than happy to handle arrays or any dimension.  For instance the Numer to Fractional String will do the job just before putting the results to the table.
Also, you need to learn about data flow.  Forget what you learned as a text based programmer.  You do not normally need to force sequencial steps by using those horrible sequence structures.  And learn to stay away from Local Variables.  They are FAR from what people think of when writing a text-based language.
To improve your program based on operator interaction, I would recommend a producer / consumer approach.  You can use the template from the File menu under > New > From Template > Frameworks > Design Patterns > Producer / Consumer Design Pattern (Events). 
Keep it simple.  Look at the example below.  I must caution that having the Apply button in the same loop as where the data is acquired is a bad approach as it may sample new data before you select the apply button.  Change the architecture.  You have to figure that one out
Attachments:
numeric2string.png ‏33 KB

Similar Messages

  • Problems with string array, please help!

    I have a String array floor[][], it has 20 rows and columns
    After I do some statement to modify it, I print this array
    out in JTextArea, why the output be like this?
    null* null....
    null null...
    null null...
    How to correct it?

    a turtle graphics applet:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class TG extends JApplet implements ActionListener {
      private int x, y;
      private int pendown, command, movement;
      String direction, output, temp;
      JLabel l1;
      JTextField tf1;
      JTextArea ta1;
      String floor[][] = new String[20][20];;
      public void init()
        x = 0;
        y = 0;
        pendown = 0;
        direction = "r";
        Container c = getContentPane();
        c.setLayout( new FlowLayout() );
           l1 = new JLabel( "Please type a command:" );
           c.add( l1 );
           tf1 = new JTextField(20);
           tf1.addActionListener( this );
           c.add( tf1 );
           ta1 = new JTextArea(20,20);
           ta1.setEditable( false );
           c.add( ta1 );
    public void actionPerformed( ActionEvent e )
           temp = tf1.getText();
           if( temp.length() > 1)
           command = Integer.parseInt(temp.substring(0,1));
           movement = Integer.parseInt(temp.substring(2,temp.length()));
           else
           command = Integer.parseInt(temp);
           switch(command)
                case 1:
                pendown=0;
                break;
                case 2:
                pendown=1;
                break;
                case 3:
                direct("r");
                break;
                case 4:
                direct("l");
                break;
                case 5:
               move(movement);           
                break;
                case 6:
                print();
                break;                                     
      public void direct(String s)
           if(direction == "r" && s =="r")
              direction = "d";
           else if(direction == "r" && s =="l")
              direction = "u";
           else if(direction == "l" && s =="r")
              direction = "u";
           else if(direction == "l" && s =="l")
              direction = "d";
           else if(direction == "u" && s =="r")
              direction = "r";
           else if(direction == "u" && s =="l")
              direction = "l";
           else if(direction == "d" && s =="r")
              direction = "l";
           else if(direction == "d" && s =="l")
              direction = "r";
      public void move(int movement)
           if(pendown == 1)
                if(direction == "u")
                for(int b=0;b<movement;b++)
                     floor[x][y+b] = "*";
                else if(direction == "d")
                for(int b=0;b<movement;b++)
                     floor[x][y-b] = "*";
                else if(direction == "l")
                for(int b=0;b<movement;b++)
                     floor[x-b][y] = "*";
                else if(direction == "r")
                for(int b=0;b<movement;b++)
                     floor[x+b][y] = "*";
            else if(pendown == 0)
                 if(direction == "u")
                for(int b=0;b<movement;b++)
                     floor[x][y+b] = "-";
                else if(direction == "d")
                for(int b=0;b<movement;b++)
                     floor[x][y-b] = "-";
                else if(direction == "l")
                for(int b=0;b<movement;b++)
                     floor[x-b][y] = "-";
                else if(direction == "r")
                for(int b=0;b<movement;b++)
                     floor[x+b][y] = "-";
          public void print()
         for(int row=0;row<20;row++)
           for( int column=0;column<20;column++)
                output += floor[row][column];
                if(column == 19)
                 output+="\n";
            ta1.setText(output);
    }

  • How do I modify an Array into a collection

    Hi I'm havin a real hard time modifying an Array into a collection, heres the code I'm working with
    I have to modify all the Arrays of this code....
    public class Student {
         private String           name;
         private float []      grades;
         private int           finalGrade;
         public Student(String name) {
              this.name      = name;
              this.grades = new float[5];
              for (int i = 0; i < grades.length; i ++) {
                   grades[i] = 0.0f;
              finalGrade = 0;
         public String toString() {
              String studentInfo = " Grades for " + name + ": ";
         for (int i = 0; i < grades.length; i ++)
         studentInfo += " " + grades;
         studentInfo += "\n final grade: " + getFinalGrade();
         return studentInfo;
         private void setFinalGrade() {
              float temp = 0.0f;
              for(int i = 0; i < grades.length; i++)
                   temp += grades[i];
              finalGrade = Math.round(temp/grades.length);
         public int getFinalGrade() {
              this.setFinalGrade();
              return finalGrade;
         public void setGrade( int index, float grade) {
              this.grades[index] = grade;
         public float[] getGrades() {
              return grades;
         public String getName() {
              return name;

    I'm kind of new at this I just started to learn about
    that, is there an example u could give me to inspire
    me ?
    Object[] o = new String[]{"one", "two", "five"};
    Collection ascollection = Arrays.asList(o);
    //the returned Collection (List) is unmodifiable,
    //so if we want to remove or add items, we need
    //a copy:
    Collection copy = new ArrayList(ascollection);
    copy.remove("two");
    String[] backagain = (String[]) copy.toArray(new String[copy.size()]);

  • Concatenation of String array.

    Hello,
    I have two string array.
    String[] szTemp1={"abc", "d e f "};
    String[] szTemp2={"123", "4-5 6"};
    How can I make a concatenation to get an array with {"123", "4-5 6", "abc", "d e f"} !
    I tried String[] szTemp2={"123", "4-5 6"} + szTemp1; but this is not working!
    Thanks in advance.
    Alain.

    From the Java API, check:
    System.arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
    Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination array. A subsequence of array components are copied from the source array referenced by src to the destination array referenced by dest. The number of components copied is equal to the length argument. The components at positions srcPos through srcPos+length-1 in the source array are copied into positions destPos through destPos+length-1, respectively, of the destination array.
    If the src and dest arguments refer to the same array object, then the copying is performed as if the components at positions srcPos through srcPos+length-1 were first copied to a temporary array with length components and then the contents of the temporary array were copied into positions destPos through destPos+length-1 of the destination array.
    If dest is null, then a NullPointerException is thrown.
    If src is null, then a NullPointerException is thrown and the destination array is not modified.
    Otherwise, if any of the following is true, an ArrayStoreException is thrown and the destination is not modified:
    The src argument refers to an object that is not an array.
    The dest argument refers to an object that is not an array.
    The src argument and dest argument refer to arrays whose component types are different primitive types.
    The src argument refers to an array with a primitive component type and the dest argument refers to an array with a reference component type.
    The src argument refers to an array with a reference component type and the dest argument refers to an array with a primitive component type.
    Otherwise, if any of the following is true, an IndexOutOfBoundsException is thrown and the destination is not modified:
    The srcPos argument is negative.
    The destPos argument is negative.
    The length argument is negative.
    srcPos+length is greater than src.length, the length of the source array.
    destPos+length is greater than dest.length, the length of the destination array.
    Otherwise, if any actual component of the source array from position srcPos through srcPos+length-1 cannot be converted to the component type of the destination array by assignment conversion, an ArrayStoreException is thrown. In this case, let k be the smallest nonnegative integer less than length such that src[srcPos+k] cannot be converted to the component type of the destination array; when the exception is thrown, source array components from positions srcPos through srcPos+k-1 will already have been copied to destination array positions destPos through destPos+k-1 and no other positions of the destination array will have been modified. (Because of the restrictions already itemized, this paragraph effectively applies only to the situation where both arrays have component types that are reference types.)
    Parameters:
    src - the source array.
    srcPos - starting position in the source array.
    dest - the destination array.
    destPos - starting position in the destination data.
    length - the number of array elements to be copied.
    Throws:
    IndexOutOfBoundsException - if copying would cause access of data outside array bounds.
    ArrayStoreException - if an element in the src array could not be stored into the dest array because of a type mismatch.
    NullPointerException - if either src or dest is null.

  • Problems with string arrays

    Previous task was:
    Write a class "QuestionAnalyser" which has a method "turnAnswerToScore". This method takes a String parameter and returns an int. The int returned depends upon the parameter:
    parameter score
    "A" 1
    "B" 2
    "C" 3
    other 0
    Alright, here's the recent task:
    Write another method "turnAnswersToScore". This method takes an array of Strings as a parameter, works out the numerical score for each array entry, and adds the scores up, returning the total.
    That's my code:
    class QuestionAnalyser{
    public static int Score;
    public String[] Answer;
    public static void main(String[] args) {}
         public int turnAnswerToScore(String[] Answer)
    for (int i = 0; i < Answer.length;i++) {
    if (Answer.equals("A")) {
    Score = Score + 1; }
    else if (Answer[i].equals("B")) {
    Score = Score + 2;}
    else if (Answer[i].equals("C")) {
    Score = Score + 3;}
    else {
    Score = Score + 0;}
    return Score;
    this is the error message I get:
    The results of trying to compile your submission and run it against a set of test data was as follows:
    ----------Compilation output--------------------------------------
    javac QATest2.java
    QATest2.java:15: cannot resolve symbol
    symbol : method turnAnswersToScore (java.lang.String[])
    location: class QuestionAnalyser
    if(qa.turnAnswersToScore(task)!=total){
    ^
    What went wrong?
    Suggestions would be greatly appreciated!

    If I declare int score in the method i get this message
    The results of trying to compile your submission and run it against a set of test data was as follows:
    ----------Compilation output--------------------------------------
    javac QATest2.java
    ./QuestionAnalyser.java:20: variable score might not have been initialized
    score++; }
    ^
    ./QuestionAnalyser.java:23: variable score might not have been initialized
    score++;
    ^
    ./QuestionAnalyser.java:27: variable score might not have been initialized
    score++;
    ^
    ./QuestionAnalyser.java:34: variable score might not have been initialized
    return score;
    ^
    4 errors
    ----------Sorry expected answer was-------------------------------
    The method turnAnswersToScore is working OK - well done!
    ----------Your answer however was---------------------------------
    Exception in thread "main" java.lang.NoClassDefFoundError: QuestionAnalyser
         at QATest2.main(QATest2.java:4)
    This is the message I get from the submission page, but trying to compile it I get the same messages.
    The code looks like this, then
    class QuestionAnalyser{
    String[] answer;
    public static void main(String[] args) {}
         public int turnAnswersToScore(String[] answer)
    int score;
    for (int i = 0; i < answer.length; i++) {
    if (answer.equals("A")) {
    score++; }
    else if (answer[i].equals("B")) {
    score++;
    score++; }
    else if (answer[i].equals("C")) {
    score++;
    score++;
    score++; }
    else {}
    return score;
    When I leave 'public int score;' where it was before (right after the class declaration below the declaration of the string array) I get this but it compiles normally.
    The results of trying to compile your submission and run it against a set of test data was as follows:
    ----------Compilation output--------------------------------------
    javac QATest2.java
    ----------Sorry expected answer was-------------------------------
    The method turnAnswersToScore is working OK - well done!
    ----------Your answer however was---------------------------------
    wrong answer in turnAnswersToScore for
    BDCAADDCA
    Alright, even university students need to sleep :-)
    Good night.

  • Remove null values from string array

    Hi ,
    I have a string array in a jsp page which I save some values inside. After I store the values I want to print only those who are not null. How can I do this? Is there a way to delete the null values?

    Thank you but because I am new in programming what do you mean to use continue. Can you explain it a little bit further?<%
    //go through the array to check all the values
    for(int i=0; i<array.length();i++) {
    //If array is null, nothing happen
    if(array==null){
    //leave here blank; instead use continue like:
    //this will skip the statements next to it, and increments the value of i in for loop and continues to execute the body of for loop.
    //The same will be repeated till the last iteration.
    continue;
    //If array not null, then print value in a new line
    else{
    out.print(array+"<br>"); //don't change the logic here
    %>

  • Getting one character at a certain position from a string array

    Hi, i'm new at learning java, but have strong experience at C++ and asm. How would i get one character at a certain positon from a string array.
    for example:
    String Phrases[] = {"To be or not to be, that is the question","The Simpsons","The Mole","Terminator three rise of the machines","The matrix"};
    that is my string array above.
    lets say i wanted to get the first character from the first element of the array which is "T", how would i get this

    ok well that didn't work, but i found getChars function can do what i want. One problem, how do i check the contents of char array defined as char Inchar[];

  • How to add elements into java string array?

    I open a file and want to put the contents in a string array. I tried as below.
    String[] names;
    s = new Scanner(new BufferedReader(new FileReader("outfile.txt")));
    while (s.hasNext()) {
                    String item = s.next();
                    item.trim();
                    email = item;
                    names = email;
                }But I know that this is a wrong way of adding elements into my string array names []. How do I do it? Thanks.

    Actually you cannot increase the size of a String array. But you can create a temp array with the lengt = lengthofarray+1 and use arraycopy method to copy all elements to new array, then you can assign the value of string at the end of the temp array
    I would use this one:
    String [] sArray = null;
    s = new Scanner(new BufferedReader(new FileReader("outfile.txt")));
    while (s.hasNext()) {
        String item = s.next();
        item.trim();
        email = item;
        sArray = addToStringArray(sArray, email);
    * Method for increasing the size of a String Array with the given string.
    * Given string will be added at the end of the String array.
    * @param sArray String array to be increased. If null, an array will be returned with one element: String s
    * @param s String to be added to the end of the array. If null, sArray will be returned.(No change)
    * @return sArray increased with String s
    public String[] addToStringArray (String[] sArray, String s){
         if (sArray == null){
              if (s!= null){
                   String[] temp = {s};
                   return temp;
              }else{
                   return null;
         }else{
              if (s!= null){
                   String[] temp = new String[sArray.length+1];
                   System.arraycopy(sArray,0,temp,0,sArray.length);
                   temp[temp.length-1] = s;
                   return temp;
              }else{
                   return sArray;
    }Edited by: mimdalli on May 4, 2009 8:22 AM
    Edited by: mimdalli on May 4, 2009 8:26 AM
    Edited by: mimdalli on May 4, 2009 8:27 AM

  • Exporting a String Array to an HTML file

    Hey everyone..I'm currently making lots of progress in my project...but right now I've been trying to make a button that exports my search results to an html file...basically what I've made is a search engine to search webcrawler files...
    The result list I get (which is actually a string array), I want to export to html so I can open that html file and find all the links that were found in the search I made..What I have so far is this, but it's not working yet, any help? :
        private class exportListener implements ActionListener
            public void actionPerformed(ActionEvent e)
                String[] result = parent.getResult();
                if(result == null)
                    return;
                JFileChooser chooser = new JFileChooser();
                chooser.setAcceptAllFileFilterUsed(false);
                chooser.setFileFilter(new HtmlFileFilter());
                chooser.setDialogType(JFileChooser.SAVE_DIALOG);
                int returnVal = chooser.showSaveDialog(parent);
                if(returnVal == JFileChooser.CANCEL_OPTION)
                    return;
                File fl = chooser.getSelectedFile();
                String path = fl.getPath() + ".html";
                searchIF.exportResultAsHtml(path);
                System.out.println(path);
        private class HtmlFileFilter extends FileFilter
            public String getDescription(){return "Html";}
            public boolean accept(File pathname)
                String name = pathname.getPath();
                //Just checking to see if the filename ends with html.
                if (name.toLowerCase().substring(name.lastIndexOf('.') + 1).equals("html"))
                    return true;
                return false;
            }

    Actually..nevermind, sorry.

  • How to populate items in selectOneListBox from a string array

    Hi
    I have got a string array result[] .Now i wish to display the array items in selectOneListBox.Please help me?

    Alance wrote:
    Hi
    I have got a string array result[] .Now i wish to display the array items in selectOneListBox.Please help me?I can only guess what your selectOneListBox is but if it is JComboBox - have you ever thought about reading the API ?
    [http://java.sun.com/javase/6/docs/api/javax/swing/JComboBox.html]
    There's a wonderful constructor which probably does what you are looking for.

  • How to use a WebService Model with String Arrays as its input  parameter

    Hi All,
    I am facing the following scenario -
    From WebDynpro Java i need to pass 2 String Arrays to a Webservice.
    The Webservice takes in 2 input String Arrays , say, Str_Arr1[] and Str_Arr2[] and returns a string output , say Str_Return.
    I am consuming this WebService in WebDynpro Java using WEB SERVICE MODEL. (NWDS 04).
    Can you please help out in how to consume a WSModel in WD where the WS requires String Arrays?

    Hi Hajra..
    chec this link...
    http://mail-archives.apache.org/mod_mbox/beehive-commits/200507.mbox/<[email protected]>
    http://www.theserverside.com/tt/articles/article.tss?l=MonsonHaefel-Column2
    Urs GS

  • Trying to compare string array using equals not working

    Hi,
    im prolly being really dumb here, but i am trying to compare 2 string arrays using the following code:
    if(array.equals(copymearray))
    System.out.println("they match");
    else
    {System.out.println("dont match");}
    the trouble is that even though they do match i keep getting dont match, can anyone tell me why?

    try
    if (Arrays.equals(array, copymearray))
    System.out.println("they match");
    else
    {System.out.println("dont match");}

  • Getting lenght of String array

    Hi,
    How can i find the lenght of a string array, i have used length method to calculate length of single string value,e.g
    String value = "test"
    int length = value.length()
    Now i want to calculate length of a string array.e.g
    String csv_values = "test,by,random"
    String[] str = csv_values.split(",")
    int lenght = str.length()
    As you can see i want to calculate total number of entries in an array after i split it dynamically.
    Currently it is giving me exception, "Unable to parse exception; Undefined method: length for class: [Ljava.lang.String]"
    Thanks

    This is a tricky one.  An Array has a length property, unlike a String which has a length method.
    So...
    int length = str.length
    Anthony Holloway
    Please use the star ratings to help drive great content to the top of searches.

  • String Array Constant Addition

    Is there an elegant way of marking the last element in a string array
    constant? i.e. I take an Array constant, and add a simple string to it,
    so that it becomes a String Array Constant. Now I add elements 1 and 2
    and 3. But now I want to take element 3 out. If I just delete Element 3
    contents from the string control, that is fine, but the # of Array
    elements is still 3. It is just that the 3rd elelment is null. How can I
    make the array length 2? Now I know that starting over is one option
    (just creat a new array constant, and add the two elements) but what if
    my array constant has 100 elements and I want to make it 99. I also
    know that programatically I can remove these elelents, but I am taking
    about in the programming of th
    is constant. I must be over looking
    something... Any ideas???
    Sent via Deja.com http://www.deja.com/
    Before you buy.

    [email protected] wrote:
    > Is there an elegant way of marking the last element in a string array
    > constant? i.e. I take an Array constant, and add a simple string to it,
    > so that it becomes a String Array Constant
    Arrays must be all the same type. If the last element is a constant, all
    elements are
    > Now I add elements 1 and 2
    > and 3. But now I want to take element 3 out. If I just delete Element 3
    > contents from the string control, that is fine, but the # of Array
    > elements is still 3. It is just that the 3rd elelment is null.
    In a string, yes, Empty strings are essentially nulls.
    > How can I
    > make the array length 2? Now I know that starting over is one option
    > (just creat a new array constant, and add the two elements) but what if
    > my array cons
    tant has 100 elements and I want to make it 99. I also
    > know that programatically I can remove these elelents, but I am taking
    > about in the programming of this constant. I must be over looking
    > something... Any ideas???
    This is one of my problems. It is easy to size an array up, but hard to size
    down.
    Of course you can resize at run time but the only way I know to do this
    when editing is to start over.
    Kevin Kent
    Attachments:
    Kevin.Kent.vcf ‏1 KB

  • String array into formula node

    Hello,
    I am taking data from SQL, I am getting multiple rows of data for many different devices. I would like to wire the data into a formula node so I can sepearate and sort via script. However, I am getting an error for "Polymorphic terminal cannot accept this data type". Is there a work around? Can I not wire in a string array to a formula node.
    /r
    Travo

    There are lots of basic string VIs that you can use to parse the string and separate out the individual fields. I would recommend "programming" your application using script nodes. Use the native language. LabVIEW is a fully functional and capable programming language.
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

Maybe you are looking for

  • Can copying a file from a Xsan volume seen thru local sharing then  be...

    I'm told this and wonder: The xsan is mounted on computer A. Computer B connects to computer A and copies a file off the Xsan that is visible because computer A is connected to it. My associate says those files copied this way that were then copied t

  • Using parallels how do you stop the default from opening in excel mac

    I am using parralells with my mac book pro, attempting to open a file in windows excel but the file keeps opeing in excel for mac, I had this working before but cannot seem to make this work now argg any help is welcome

  • Error: "Couldn't create Crystal Reports Engine for report format version 10.0"

    Post Author: mkubala CA Forum: Crystal Reports I created several reports in ClearQuest v2003.6.15 using Crystal Reports v10. When a user tries to run these reports from his machine he gets the following error:"Problems executing ReportContact your Cl

  • Filter a Report

    Hi all, I'm having trouble with filtering my report.  Can someone help me with querying a report by a client's name.  I'm not sure how to do that with a blank report. Thank you, Sophal

  • Procurement of Direct Materials in SAP SUS

    Hi gurus, I need a supplier portal, my client wants that suppliers can confirm PO directly, not calling to the purchaser. I have read that Supplier Self-Services (SUS) and SAP Materials Management (SAP MM) can be used in conjunction with each other.