LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to basically append elements to an array, so the string array get bigger and bigger

So another question: 


I have an array of integers, which is like 50 elements long. I only want to pick out element 9,10 and 25. It could be I in the future would like to pickout 9,10,21,25,34 and some other elements.

 

So the way I did this is with "Index Array", and then pickout the required elements of the array. Fine enough. However, I need to cast them to a string, where I am then using the "Format into String". 

I wanted to make a for loop, which should run as many times there is elements, that I have picked, i.e. three times in this example, and then inside the for loop have one "Format into string", which then takes the first element, convert that into a string and then append that to a new array. 

However I was not able to do that. I tried shift registers but it just not quite went good 🙂 

ChristianLiinHansen_0-1635325192895.png

So basically, is there a way to do this better with a for loop? Because, the code now is not very scalable and if I e.g. wants like 10 elements, this would be a nightmare to write like above. Therefore a for loop implementation is what I am looking for basically. The basic questions is then: 

1) How do I start with an 1-d array, with only 1 element, and then in the next iteration of the for loop, I append the next element into the old 1d array, so that it grows to 2 elements, and so forth. I.e. the string array should look like this:

i = 0 --> string array =  [string1]
i = 1 --> string array =  [string1, string2]
i = 2 --> string array =  [string1, string2, string 3]

...
i = n --> string array =  [string1, string2, ... ,  string-n]



 

0 Kudos
Message 1 of 10
(1,364 Views)

Please attach your code, not just a picture. Also, please do save relevant default data in the "Input Registers" control.

0 Kudos
Message 2 of 10
(1,326 Views)

Hi ChristianLiinHansen,

 

You can loop the array of elements you want to pick through the for loop so it will check your array and output desired value. Then it'll build the array of string to which you can concatenate date and time as you have shown.

 

is this what you're looking for?

appendelements.png

_______________________________________________________________

-Patrik
CLA || CTA
If it helps - Kudo it, if it answers - Mark As Solution
0 Kudos
Message 3 of 10
(1,313 Views)

Ajskrim beat me too it...

Frozen_0-1635342728932.png

 

---------------------------------------------
Certified LabVIEW Developer (CLD)
Message 4 of 10
(1,310 Views)

What is the name of the last block with the number "999"?

0 Kudos
Message 5 of 10
(1,268 Views)

"number to decimal string"

0 Kudos
Message 6 of 10
(1,264 Views)

@ChristianLiinHansen wrote:

1) How do I start with an 1-d array, with only 1 element, and then in the next iteration of the for loop, I append the next element into the old 1d array, so that it grows to 2 elements, and so forth. I.e. the string array should look like this:

i = 0 --> string array =  [string1]
i = 1 --> string array =  [string1, string2]
i = 2 --> string array =  [string1, string2, string 3]

...
i = n --> string array =  [string1, string2, ... ,  string-n]


Array With Strings.png

0 Kudos
Message 7 of 10
(1,248 Views)

Well, you don't really need all these intermediary results, right? Do the following to get the final output directly:

 

altenbach_0-1635783774491.png

 

NOTE: You even get a linefeed at the end so each appended string gets a new line in the file. You can use "trim whiltespace" if you don't want that.

 

0 Kudos
Message 8 of 10
(1,234 Views)

@altenbach wrote:

Well, you don't really need all these intermediary results, right? Do the following to get the final output directly:


I don't

 

I don't see much use in it either,  but it was explicitly requested in the OP...

0 Kudos
Message 9 of 10
(1,223 Views)

Yes, I was replying to the OP. 😄

Message 10 of 10
(1,215 Views)