02-04-2012 07:47 AM
Hello,
I have a string array containing numbers in engineering format such as below:
5.34000E-10
3.23245E-1
-8.43560E-9
I am trying to concatenate this string array to a header, which is a single string formed by using the concatenate strings function. So, I would like my output to read:
Header line 1
Header line 2
Header Line 3
5.34000E-10
3.23245E-1
-8.43560E-9
However, the output currently reads:
Header line 1
Header line 2
Header Line 3
5.34000E-103.23245E-1-8.43560E-9
I can get the desired output using a for loop, but I do not want to do that as the concatenate strings function seems to run very slow within the loop. Is there a way I can get the desired output without using a for loop?
Thanks.
Solved! Go to Solution.
02-04-2012 08:34 AM
and your code is???
02-04-2012 09:31 AM
02-04-2012 10:08 AM
@newbie81 wrote:
I can get the desired output using a for loop, but I do not want to do that as the concatenate strings function seems to run very slow within the loop. Is there a way I can get the desired output without using a for loop?
That a silly statement! For all practical purpose, a FOR loop is as fast as any other code doing the same stuff and it has the advantage of a cleaner diagram in the typical case of doing repetitive work. If your code is slow by any definition, obviously you are doing something wrong, however we cannot tell, since you are not showing what you are doing. Please attach your VI with some typical sample data so we can explain what is wrong an everybody learns something.
Of course there are loop-free solutions (such as Gerd's first example), but one way or another, that function has internal loops too. There is no multipurpose CPU in existence that can concatenate a large string array with only a few CPU instruction. :o:D.
02-04-2012 11:17 AM - edited 02-04-2012 11:18 AM
And, If you really hate concatenating inside a for loop. Just auto index your string array out of the for loop and wire the array to the concatenate strings input outside the loop. (Yes, concatenate strings accepts arrays )
02-04-2012 02:14 PM
02-14-2012 06:35 AM
The example I presented was simplistic to show the concept. I actually have to write a citifile with on the order of 1000 rows and 2 columns. I inherited code which does this using a for loop, and it takes approximately 13 seconds to process - waaay too slow in my opinion. I also have a correction - the loop was not using Concatenate Strings . Rather, it was converting each row to a string using Format Value.
I have an example of my current solution attached. I first build an array containing the header information, which are read as strings. I then have an nx1 array of numeric data, which is how it is read from the instrument. I convert this 1D array to an (n/2)x2 array using Disseminate 1D Array, convert this array to a string array and write to file using Write To Spreadsheet File with a comma as the delimeter.
This seems to work, but I have not applied it to my main VI yet....