LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to operate this one-degree array?

i have a one-degree array like the following:

0 0 0 2 3 4 5
how to move 2,3,4,5 to the first four position to form the result like this:
2 3 4 5 0 0 0

thanks!
0 Kudos
Message 1 of 6
(2,978 Views)
Try the attached vi. If you can't read the file then here is a description

1. Reverse the array and get the array length
2. Search the reversed array for the first zero
3. Subtract this number from the array length
4. Use this number to split the original array
5. Take the two new array and concatenate them in reverse order.
Randall Pursley
0 Kudos
Message 2 of 6
(2,977 Views)
If you always have 3 leading zeroes, just use "rotate array" with n = -3.

If you have a variable amount of leading zeroes and want to programmatically determine how much to rotate to get the first nonzero number at the beginning, use something like the simple code attached.
0 Kudos
Message 3 of 6
(2,968 Views)

@rpursley8 wrote:
2. Search the reversed array for the first zero

Randall, You are making the assumption that ALL elements after the first nonzero element are always nonzero. For example an input of 0,0,0,2,3,0,5 to your code would yield 5,0,0,0,2,3,0 which is probably not as intended. My code results in 2,3,0,5,0,0,0 for this case, which seems more reasonable.
0 Kudos
Message 4 of 6
(2,955 Views)
Why not use the 'Delete From Array' / 'Insert into Array' functions of LabVIEW. Depending on your application, it may be a little more robust.

Take a look at this.

Jerry
0 Kudos
Message 5 of 6
(2,936 Views)
I am assuming the all the zeros will be in front because since all of the number were in ascending order, the array looked like it was sorted to me.
Randall Pursley
0 Kudos
Message 6 of 6
(2,932 Views)