03-02-2012 08:44 AM
Hello,
I was wondering how to do something.
Let's say for example that my input is an array of numbers. One thing I know is that the integers are all sequential, but with gaps inbetween. Something like this:
3,4,5,9,10,11,12,16,17, 18,....
Not so important for this issue, but if you want more background : Each of these numbers correspond to an index of another array, which is the analog input array.
What I want to get is all the subarrays, without the gaps, so for the example above:
3,4,5
9,10,11,12
16,17,18
.
.
.
Background again: Later I will have to compare the values to which these numbers correspond to see which one is the highest and just keep the index of the highest number.
If you don't have time to give an example code, I'd be delighted with a simple idea too 🙂
I've tried putting in my array into a loop twice, checking one value incremented by one with the next value, but all of this gets very complicated when trying to build arrays again. I was thiking of using "index array" to get the sub arrays or "split 1D array" to do it instead.
Thanks in advance,
David.
Solved! Go to Solution.
03-02-2012 08:57 AM
just an idea for you to try. step through the array starting at index 0. find the difference between the current element and the previous element (need a shift register). If this is greater than 1 you have found the start of the next subarray. The loop count will give you the index to split the main array. repeat until main array been examined.
There may be some bugs in the logic but hopefully given you an idea of a way to approach it.
TD
03-02-2012 09:03 AM
03-02-2012 09:07 AM
I don't really understand what you mean. I'm currently trying out Tdarkins way though.
You're saying that won't work though, aren't you ?
03-02-2012 09:10 AM
not sure a cluster of arrays would be ideal, i am presuming the values in the subarrays will inturn be used to index other arrays. the arrays could be placed into a queue (producer/consumer setup).
TD
03-02-2012 09:25 AM
@Pladio wrote:
I don't really understand what you mean. I'm currently trying out Tdarkins way though.
You're saying that won't work though, aren't you ?
What do you want the function to output? It sounded like you want it to output several arrays from one input array. LabVIEW does not support arrays of arrays so you would need an array of clusters of arrays. Of course you could output an array containing the indexes of the "subarrays". That is another way to do it.
03-02-2012 09:30 AM
I've attached screenshots. Is that what you meant ?
It seems to be quarter-working ... It manages to get 2,3,4,5 and then fails with the rest. I've probably done something wrong, but it seems to be going in the right direction. I'll try finding out what the problem is, but I might not be able to, so I won't mind more help 🙂
Thanks 🙂
03-02-2012 09:32 AM
the method i outlined will split the array where you would like, but does not detail what happens to the data next, steves right LV does not allow array of arrays, so you will have to decide what to do with the sub arrays, a cluster of arrays is one way, placing them in a queue another, or you could use the information in them straight away amoungst other methods
TD
03-02-2012 09:35 AM
TD, it doesn't seem to be splitting it correctly yet though. I might have a mistake as I outlined in my previous reply. I'm trying to figure it out.
03-02-2012 09:37 AM
I was aiming to make some suggestions that would help you work it out instead of posting a solution, by the sounds of it you have an idea of how to do it its just the actual implementation, so you should be able to work it out
TD