LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Parsing a long 1D array into subarrays of values according to condition(s)

Dear LabVIEW experts,

 

I have a long 1D array that looks like this:

[0,1,2,3,4,5,0,0,88,99,11,24,56,120,0,0,0,0,78.5, 66.8,32, 0,0,0,0,...]

I will need to parse the long 1D array into smaller arrays that contains elements that are greater than zero. For example, [[1,2,3,4,5], [88,99,11,24,56,120], [78.5, 66.8, 32]], and so on.

Note that I am aware of the consequence of storing 1D arrays of different length into a 2D array: the shorter ones will be pad but that is not a concern to me.

I was managed to do it by looping through the long 1D array first, then noting down where the indices on non-zero elements are, and then have the indices array feed into second for loop to extract the elements I want. Please find the attched parse_array_method1.vi for the code. However, I think there might be an easier/elegent solution to this, so I tried another method, which is available in parse_array_method2.vi.

My idea was looping through the long 1D array, then check if the elementi is greater than 0. If yes, the value will be feed into the "TRUE" case and then into a while loop. When the element hits zero while loop will release the subarray into the outer for loop. Somehow my code did not work and I cannot figure out why.

 

Can you please suggest what's wrong with my second code? Also, are there any other methods to achieve the same goal?

Thank you.

Download All
0 Kudos
Message 1 of 3
(865 Views)

Hi cztee,

 

just to give an idea, even though it's not perfect:

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 3
(842 Views)

@cztee wrote:

Dear LabVIEW experts,

 

Note that I am aware of the consequence of storing 1D arrays of different length into a 2D array: the shorter ones will be pad but that is not a concern to me.


If you don't care about padding, then the following may work. (Not thoroughly vetted)

If you do care about the padding, then put the subarray in a cluster and and make an array of ragged clusters. (2018 Version Attached)

 

Padded 2D ArrayPadded 2D Array

Array of ragged clustersArray of ragged clusters

0 Kudos
Message 3 of 3
(823 Views)