04-19-2023 11:28 AM - edited 04-19-2023 11:33 AM
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.
04-19-2023 12:51 PM - edited 04-19-2023 12:54 PM
04-19-2023 02:08 PM
@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)