topic Re: How to compare consecutive groups of numbers in arrays in LabVIEW
https://forums.ni.com/t5/LabVIEW/How-to-compare-consecutive-groups-of-numbers-in-arrays/m-p/2335050#M731305
<P>Hi Johnsold</P>
<P> </P>
<P>1. Both input arrays the data is in descending order</P>
<P>2. One output array. (The vi only has several to help you do better than what l have achieved)</P>
<P>3. Yes. Your output is correct</P>
<P>4. In the end the size of an image. Very large no limit set. The 1D arrays are part of other code which l do not want to side track you with.</P>
<P> </P>
<P>Thanks Lynn</P>Sun, 03 Mar 2013 03:01:37 GMTwetland2013-03-03T03:01:37ZHow to compare consecutive groups of numbers in arrays
https://forums.ni.com/t5/LabVIEW/How-to-compare-consecutive-groups-of-numbers-in-arrays/m-p/2335028#M731298
<P>Hi</P>
<P> </P>
<P>I require to place the solution into a 1D array.</P>
<P>I need to compare two arrays and save the same numbers that are in both arrays but also save groups of numbers that may be in only one of the two arrays being compared.</P>
<P> </P>
<P><FONT color="#ff0000"><STRONG>In the example l have not been able to place all consecutive groups of numbers 8,9,10,11,12 into a 1D array.</STRONG></FONT></P>
<P> </P>
<P>In the example l need to filter out the zeros and the number four.</P>
<P>The numbers in both arrays are always in descending order however may not be in the order of index number of array. That is 15 = 15 index number</P>
<P>A consecutive group of numbers in this example is a group that increase by a value of 1. E.g.. 8,9,0,22,23,24 are two consecutive groups of numbers.</P>
<P> </P>
<P>Thank you</P>Sun, 03 Mar 2013 00:49:35 GMThttps://forums.ni.com/t5/LabVIEW/How-to-compare-consecutive-groups-of-numbers-in-arrays/m-p/2335028#M731298wetland2013-03-03T00:49:35ZRe: How to compare consecutive groups of numbers in arrays
https://forums.ni.com/t5/LabVIEW/How-to-compare-consecutive-groups-of-numbers-in-arrays/m-p/2335044#M731304
<P>Let me see if I understand what you want. It seems you have multiple conditions.</P>
<P> </P>
<P>1. No zeros are in the output array.</P>
<P>2. Any non-zero value in both input arrays will be in the output array.</P>
<P>3. Any series of consecutive numbers in either input array will be in the output array.</P>
<P>4. You mention descending order but your examples and code are in ascending order. Which do you want?</P>
<P> </P>
<P>Questions:</P>
<P>1. Are the input arrays sorted or known to be in ascending (or descending) order?</P>
<P>2. How many output arrays do you want? Your VI has several.</P>
<P>3. If the two input arrays have series of consecutive numbers which do not appear in both arrays but are consecutive to each other, do they appear in the output array as one series? Example Array has [2,3,4,0,0,8,17,25] and Array 2 has [0,0,5,6,7,10,14]. Is the output array [2,3,4,5,6,7,8] or something else?</P>
<P>4. How big is the largest array you will ever process?</P>
<P> </P>
<P>Lynn</P>Sun, 03 Mar 2013 01:42:07 GMThttps://forums.ni.com/t5/LabVIEW/How-to-compare-consecutive-groups-of-numbers-in-arrays/m-p/2335044#M731304johnsold2013-03-03T01:42:07ZRe: How to compare consecutive groups of numbers in arrays
https://forums.ni.com/t5/LabVIEW/How-to-compare-consecutive-groups-of-numbers-in-arrays/m-p/2335050#M731305
<P>Hi Johnsold</P>
<P> </P>
<P>1. Both input arrays the data is in descending order</P>
<P>2. One output array. (The vi only has several to help you do better than what l have achieved)</P>
<P>3. Yes. Your output is correct</P>
<P>4. In the end the size of an image. Very large no limit set. The 1D arrays are part of other code which l do not want to side track you with.</P>
<P> </P>
<P>Thanks Lynn</P>Sun, 03 Mar 2013 03:01:37 GMThttps://forums.ni.com/t5/LabVIEW/How-to-compare-consecutive-groups-of-numbers-in-arrays/m-p/2335050#M731305wetland2013-03-03T03:01:37ZRe: How to compare consecutive groups of numbers in arrays
https://forums.ni.com/t5/LabVIEW/How-to-compare-consecutive-groups-of-numbers-in-arrays/m-p/2335052#M731306
<P>Hi Lynn</P>
<P> </P>
<P>Sorry 1. Both input arrays are in ascending order. That is 1, 2 ,3 etc</P>Sun, 03 Mar 2013 03:04:15 GMThttps://forums.ni.com/t5/LabVIEW/How-to-compare-consecutive-groups-of-numbers-in-arrays/m-p/2335052#M731306wetland2013-03-03T03:04:15ZRe: How to compare consecutive groups of numbers in arrays
https://forums.ni.com/t5/LabVIEW/How-to-compare-consecutive-groups-of-numbers-in-arrays/m-p/2335244#M731351
<P>This turned into a bit more of a challenge than I initially anticipated.</P>
<P> </P>
<P>The attached VI shows one way to do parts of what you want.</P>
<P> </P>
<P>The part at the lower left finds non-zero duplicates. I use Replace Array Subset as it is much more memory efficient than Insert into Array. I initialize the output array with the size of the smaller of the two input arrays because there can never be more duplicates than elements in the shorter array. After the loops the Array Subset eliminates any excess elements.</P>
<P> </P>
<P>The part at the lower right finds consecutive elements in one array. It is initialized to the size of the array being tested, because that is the size required if every element is successive to the previous element. The logic is described on the block diagram.</P>
<P> </P>
<P>For the complete process you require the lower left part would need to be repeated for the other input array. Then the three output arrays (Duplicates, Consecutive 1, and Consecutive 2) would need to be run through the duplicates loop (2 passes) with the logic reversed to remove duplicates. Thst will generate the desired output array. Because much of the code will be used two or three times, it should be made into subVIs. These parts I leave for you.</P>
<P> </P>
<P>After you get it working, take a careful look at the memory requirements. Since you will be working with images, your arrays may get quite large. Look at the white paper on Handling Large Data Sets on NI's web site. I did not search for the exact title. It has much good information on hanlding large arrays.</P>
<P> </P>
<P>Lynn</P>Sun, 03 Mar 2013 16:57:26 GMThttps://forums.ni.com/t5/LabVIEW/How-to-compare-consecutive-groups-of-numbers-in-arrays/m-p/2335244#M731351johnsold2013-03-03T16:57:26ZRe: How to compare consecutive groups of numbers in arrays
https://forums.ni.com/t5/LabVIEW/How-to-compare-consecutive-groups-of-numbers-in-arrays/m-p/2337192#M731732
<P>Hi Lynn</P>
<P> </P>
<P>You have done a very good job. I gone on at work and preformed correctional code which is turning into a mountain.</P>
<P> </P>
<P>When providing a example for help l have tried to make it simple as possible. So when changing numbers l found two cases where the code was not robust that is changing 0,4,0 to either 0,6,6 (does not pick up the two 6's) or 4,6,6 (picks up all three numbers instead of only the two 6's). Don't worry you have provided a new approach to this old problem of mind.</P>
<P> </P>
<P>I have not used all the new LV 2012 for loop features as yet like the conditional stop on the for loop. Good to see that in use. I am still in the LV8.6.1 mind set.</P>
<P> </P>
<P>When you started to solve this problem did you first work it out on paper like a math's problem?</P>
<P> </P>
<P>At the moment at work l have approached the job l am doing differently because l do not know how much array code l require. The second reason l am approaching the job this way is l am to make my first LVOOP project and using in place element structure for the first time to handle memory by using is around each group of data types for each group of arrays.</P>
<P> </P>
<P>I am happy to go away with your solved solution. I will hit the accept button after l have seen your reply</P>
<P> </P>
<P>Thank you Lynn.</P>
<P> </P>
<P> </P>Tue, 05 Mar 2013 10:38:56 GMThttps://forums.ni.com/t5/LabVIEW/How-to-compare-consecutive-groups-of-numbers-in-arrays/m-p/2337192#M731732wetland2013-03-05T10:38:56ZRe: How to compare consecutive groups of numbers in arrays
https://forums.ni.com/t5/LabVIEW/How-to-compare-consecutive-groups-of-numbers-in-arrays/m-p/2337832#M731834
<P>Hi Lynn</P>
<P> </P>
<P>I just realized in this case 6,6 would not occur it would always jump up to 6,7. I was thinking of another array.</P>
<P> </P>
<P>I will test the array at work and provide feedback</P>
<P> </P>
<P>Thanks</P>
<P> </P>
<P>Lynn again</P>Tue, 05 Mar 2013 17:46:53 GMThttps://forums.ni.com/t5/LabVIEW/How-to-compare-consecutive-groups-of-numbers-in-arrays/m-p/2337832#M731834wetland2013-03-05T17:46:53ZRe: How to compare consecutive groups of numbers in arrays
https://forums.ni.com/t5/LabVIEW/How-to-compare-consecutive-groups-of-numbers-in-arrays/m-p/2338368#M731912
<P>I am sure there may be border cases which are not handled correctly. One is the case where a zero occurs between consecutive values. [4,5,0,0,6,...]. If this should return [4,5,6], I think my code would fail because it resets on detecting a zero.</P>
<P> </P>
<P>If you have knowledge of your process which can be used to make it more robust or to set limits on the size of the output arrays, that should be added. I made the output arrays large enough to handle the worst case. If you know for example that never more than 100 consecutive values will be in the data, those arrays could be initialized to size = 100.</P>
<P> </P>
<P>I did not write out long arrays on paper but I did draw some flow charts which describe the same logic that I attempted to put into the comments at the bottom of the BD. It would be nice if there were easy ways to document flow charts on a diagram.</P>
<P> </P>
<P>Another array based approach which I considered for the consecutive values part was to add 1 to the array and then compare The original array A and the added array A' for duplicate values. This requires allocating space for a second copy of the original array, so I did not follow up on this method.</P>
<P> </P>
<P>I did not consider either LVOOP or the in place structure but both could be investigated.</P>
<P> </P>
<P>Lynn</P>Wed, 06 Mar 2013 03:32:15 GMThttps://forums.ni.com/t5/LabVIEW/How-to-compare-consecutive-groups-of-numbers-in-arrays/m-p/2338368#M731912johnsold2013-03-06T03:32:15ZRe: How to compare consecutive groups of numbers in arrays
https://forums.ni.com/t5/LabVIEW/How-to-compare-consecutive-groups-of-numbers-in-arrays/m-p/2340436#M732292
<P>Hi Lynn</P>
<P> </P>
<P>I did have a look at the consecutive array solution. I have looked and looked l thought l knew how it worked but after a number of separate evaluations with other code l have failed. I am just glad it works. With the consecutive array solution l tried today my own code but l lost either the first number of the last number of a consecutive group of numbers.</P>
<P> </P>
<P>I may have confused you but in doing so you have provided a real different view which l am very grateful. You have viewed the consecutive number problem as just a single 1D array problem. By doing this you have opened my eyes to another way to do the job and a way to handle this type of data. However l am also comparing two arrays. For example l have to pick up say two equal values in two columns that the consecutive array does not detect and then correctly locate a value in the final array if the value is not in the final array.</P>
<P> </P>
<P>What l have not told you is also l have to be able to identify groups of numbers in two 1D arrays. E.g... Array 1 has 1,2,9,10 next array has 9,10 the final array ends up 9,10 when l would like 0,9,10. When viewing numbers by rows later on l can then detect with a array length vi the length of the 1,2 groups of numbers over a large number of columns. If 9,10 jumps to the front it becomes a wrong length. This is actually my main problem which has caused me a large amount of extra programming. I have gone back to basics to see what l can do differently and you have provided the first clue with the consecutive array. I placed it in my main program today and it filtered a lot variable data which l could not remove without losing real data. The main data lost in your solution was the say 17 number in two columns which in an image is a horizontal line. I know what l have just provided you in this paragraph is all new information but it provides a background as to what l am up to. I am getting pixel data from a 2D array and comparing +1 index 1D array with a normal array. This way l can view the data of the next column to see if there is a pattern. I am actually trying to program an array as how humans view objects in images.</P>
<P> </P>
<P>I will have another go at integrating your solution next week</P>
<P> </P>
<P>Regards</P>
<P> </P>
<P>Michael</P>Thu, 07 Mar 2013 09:27:23 GMThttps://forums.ni.com/t5/LabVIEW/How-to-compare-consecutive-groups-of-numbers-in-arrays/m-p/2340436#M732292wetland2013-03-07T09:27:23ZRe: How to compare consecutive groups of numbers in arrays
https://forums.ni.com/t5/LabVIEW/How-to-compare-consecutive-groups-of-numbers-in-arrays/m-p/2340618#M732319
<P>Hi Lynn</P>
<P> </P>
<P>I have just stopped programming. I still have to finish what l stated in my last message but it is nearly complete. I am going bush for the next 4 days to cool off a little. It's been 30 +C for a number of days now.</P>
<P> </P>
<UL>
<LI>When you will see the code l have developed around your beautiful consecutive array solution l will need some help to reduce the size of the code. I have already 7 extra for loops. Compacting code is not my best feature.</LI>
</UL>
<P> </P>
<P>I will send the vi next week.</P>
<P> </P>
<P>Regards</P>
<P> </P>
<P>Michael</P>Thu, 07 Mar 2013 12:30:45 GMThttps://forums.ni.com/t5/LabVIEW/How-to-compare-consecutive-groups-of-numbers-in-arrays/m-p/2340618#M732319wetland2013-03-07T12:30:45ZRe: How to compare consecutive groups of numbers in arrays
https://forums.ni.com/t5/LabVIEW/How-to-compare-consecutive-groups-of-numbers-in-arrays/m-p/2341884#M732558
<P>Michael,</P>
<P> </P>
<P>Enjoy your break!</P>
<P> </P>
<P>Post back when you get stuck again. Do not worry that you may not have compact or efficient code. That can take lots of time and experience. Sometimes you need to try several different versions to see what works best for your data.</P>
<P> </P>
<P>Lynn</P>Fri, 08 Mar 2013 01:48:20 GMThttps://forums.ni.com/t5/LabVIEW/How-to-compare-consecutive-groups-of-numbers-in-arrays/m-p/2341884#M732558johnsold2013-03-08T01:48:20ZRe: How to compare consecutive groups of numbers in arrays
https://forums.ni.com/t5/LabVIEW/How-to-compare-consecutive-groups-of-numbers-in-arrays/m-p/2344534#M733012
<P>Hi Lynn</P>
<P> </P>
<P>I am not stuck now and l am very grateful for your help. I think your array is just brilliant. So it seems l do not need to provide any more messages</P>
<P> </P>
<P>Again Thank you</P>
<P> </P>
<P>Michael</P>Mon, 11 Mar 2013 09:13:33 GMThttps://forums.ni.com/t5/LabVIEW/How-to-compare-consecutive-groups-of-numbers-in-arrays/m-p/2344534#M733012wetland2013-03-11T09:13:33Z