I have large set of data in an array and i want to group them to a particular value by averaging them and know their lower index and the max index of that particular avg value.With the tolerance setting ,say 5 for this example.The group of data need to avg and get the index of the frist value and the last value of the particular set of data
i hope there is simple way to do this ?
The question is not necessarily "Can you do it?" but "What is the best approach in terms of performance?".
This is a first draft, which is, performance wise, not very elegant:
I say so as it deletes the segments from the original array which is a quite resource-intensive procedure and will fragment your memory.
But, it is easy code and it will do what you need.
And here another approach which should perform a little nicer in context of memory fragmentation (so less fragmentation). I also added Min/Max values. I don't create the clusters with Min/Max/Average value as array, that is something you can add.
Norbert_B Thanks for the reply,
I am not sure you got my question right. I see your taking a set of 5 data and taking the average. But In my data ,i not sure of how many data is inside my tolerance .It can be 10,20 or even 1. so i need to find the set of that data and take their avg and mention the index from where it starts(min Index) and end(max Index).
In that case you can replace the constant "5" with a 1D array of tolerances. Will that work for you?
Hm, i think i understand what you mean with "tolerance". That makes indeed things more complex.
Point is: How do you define "tolerance"?
Your array has value '1' at index 0. So a tolerance of 5 means, that any value <-4 or >6 in any following index is "out of tolerance" and therefore results in a new segment?
my idea was to take the first element and comapre with the next element.Is the value inside tolerance .taking my example in the fig .i take my frist data 1 that will write the min index =0 ,then i check with the next data 2 .is 2 inside the tolerance of 1+5/-5 ,if yes group that data with 1 by averaging .same to be done for the next value and so on. when the data reaches 15.Is 15 inside the tolerence of 1+5/-5 NO ,so the max index of the prev group (1's avg )is (present index-1)ie 4 as in example .And the min index of 15's data group is 5 .Now taking 15 ,doing the same as we did for 1st data. store all the set of data into cluster array I guess this idea will work ,but not able to exectue this .need help in doing this.
I think, as modern PCs have a real high performing CPU, that you shouldn't focus too much on performance, but on code design.
I recommend you to create a flow chart or state diagram showing what your program has to do. Simple put: Transform your description into a diagram for code design.
Once you did that, you have to implement your diagram step-by-step in LV. If you chose the state diagram, a simple state machine would be the LV code architecture you would pick to implement your diagram with.
Remember to use shift registers for data you require in multiple states with the option to modify that data in single states.