04-08-2010 04:54 PM - edited 04-08-2010 04:55 PM
Hi folks,
It looks like you are pretty much got there thanks to Nathan's fine work. I found this a difficult but fun problem. I know this is not ideal but I wanted to float the idea of using this function to create two arrays that you could logical AND to check for overlap.
This is the function
Now there are some issues here in my code. Span will create ranges of length 1,3,5 ... so that needs to be better defined for even number spans. I know I am a bit late and probably not perfect to your needs. However I did the work and I thought might as well share it just in case it sparks furher ideas for the topic.
cheers
David
04-12-2010 09:04 AM
That's just about the same solution I had previously, so I guess I'll stick with it. Thanks for taking the time to explore my problem.
nathand wrote:
elset191 wrote:That doesn't quite work. At least one case I have checked is when one range is completely within the other. For example, (87,8) and (85,2) should remain 8 span (and center 87), but the method you described gives 7. It's not always off by one, (87,8) and (87,2) gives 5, for instance.
Good point; I should have tested more thoroughly before suggesting that. This has been a fascinating way to be unproductive for a few hours today, and if I'm ever looking for a programming puzzle for someone maybe I'll suggest this. It may not be the most efficient implementation but I'm pretty sure the code below does what you need. If I missed another case let me know.
04-12-2010 09:58 AM
elset191 wrote:That's just about the same solution I had previously, so I guess I'll stick with it. Thanks for taking the time to explore my problem.
nathand wrote:
elset191 wrote:That doesn't quite work. At least one case I have checked is when one range is completely within the other. For example, (87,8) and (85,2) should remain 8 span (and center 87), but the method you described gives 7. It's not always off by one, (87,8) and (87,2) gives 5, for instance.
Good point; I should have tested more thoroughly before suggesting that. This has been a fascinating way to be unproductive for a few hours today, and if I'm ever looking for a programming puzzle for someone maybe I'll suggest this. It may not be the most efficient implementation but I'm pretty sure the code below does what you need. If I missed another case let me know.
The only modification I made was to replace the select part with a mod. Thanks again.
04-12-2010 03:08 PM
Further testing exposed an error in the super-range code. (250,8) and (2,8) returns a center of 128 and span of 256.
This case fails in my original code too.
04-13-2010 08:51 AM
Hi Elset,
I had a go at your problem and have posted below. I think i get what you are trying to do but not 100% sure:
Am i correct in saying that the new span will be between the overlapped highest point to lowest point, and the new centre the value in the centre of these 2 points? This VI does that. One thing that i noticed whilst playing around with it is that if this is what you are after you may get funny results. For some circumstances the Overlapped Maximum and minimum points will have an uneven span, say 13. This will mean the centre value will not be an absolute value but be n + 0.5. I would assume that this will not be what you are after but this is what you'll get as you cannot control how the 2 ranges overlap.
Hope this has helped. If i have misunderstood give me more details and i will have another go for you.
Rgs,
Lucither
04-13-2010 10:30 AM
Hey Lucither,
So far it seems to do exactly what I need. So far it has passed all the test cases that have given me trouble throughout the different iterations. I'll continue to try and break it though.
Also, I've cleaned it up, removing a lot of selects and case structures
The main In Range Check VI
The Get Span and Center VI. (The subvi just does the plus and minus of span/2)
04-13-2010 10:54 AM
Hi Else
Im not sure that you can use the Max Min vi to correctly sort the range1 and range2. If you do what you have done then it will return a cluster containing the 2 highest values and 1 containing the lowest. For it to work correctly though the correct span has to be kept with its own center. This could cause them to change. for example, if you have range 1 = centre:100, span:0 and range2 = centre:87, span:3. it will return a range of 100:0 and 87:3, this will give you incorrect readings when trying to calculate the new centre and span. you need to sort the ranges by order of just the centres but keep the spans with there original centres.
Glad its working so far though
04-13-2010 10:58 AM - edited 04-13-2010 11:00 AM
Change the comparison mode on the Max & Min from Compare Elements to Compare Aggregates and it works correctly. This way it compares the first element. (then if it is equal it will look at the second, and so on)
Lucither wrote:Hi Else
Im not sure that you can use the Max Min vi to correctly sort the range1 and range2. If you do what you have done then it will return a cluster containing the 2 highest values and 1 containing the lowest. For it to work correctly though the correct span has to be kept with its own center. This could cause them to change. for example, if you have range 1 = centre:100, span:0 and range2 = centre:87, span:3. it will return a range of 100:0 and 87:3, this will give you incorrect readings when trying to calculate the new centre and span. you need to sort the ranges by order of just the centres but keep the spans with there original centres.
Glad its working so far though
04-13-2010 11:01 AM
Hi Else,
Yeah, your right, just tested. Have never used that mode before. Have learnt something new, thanks.
04-13-2010 11:03 AM
elset191 wrote:
Change the comparison mode on the Max & Min from Compare Elements to Compare Aggregates and it works correctly. This way it compares just the first element I believe.
It compares the first element, and if they're equal, then it compares the second element (and then the third, etc). This is the same way that Sort 1D Array works when passed an array of clusters, and it is a very useful technique to know for sorting by criteria in order of preference (arrange your cluster so that the most important element is first, the next most second).