LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Calculating statistics from an array with intervals

Hello,

I have a 2D-array, column 0 contains the time of the measurement and column 1 the acquired data.
Within a For-loop I check the elements for column 0 one by one if they are within a certain interval (e.g. for interval 1 the element should be >= 0 and < 4, for interval 2 >=4 and <8, etc).
For each element for column 0 that is within the current interval the corresponding element for column 1 is added to an array with the previous elements of column 1 for that interval, this array is passed to the next iteration with a shift register until the value for element x of column 0 is within the next interval (=2). Then some statistics (number of samples, summation�) of the array containing the values for inter
val 1 are calculated. These statistics are stored / added in / to an array containing the previous statistics. Then the next element of column 0 for interval 2 is checked and so on.

All the above works fine until there are no values within an interval, e.g:
Data array: {{1,3,5,13,15,17,18},{2,3,2,1,3,4,1}} should result in the following array: {{2,1,0,2,2},{5,2,0,4,5}}, but instead it displays: {{2,1,1,1,2},{5,2,1,3,5}}. The vi treats value 13 of column 0 as it belongs to interval 3 although it actually belongs to interval 4.

I tried several options but none of them gave the desired result and now I have run more or less into a dead end. Could anyone please help me or give me a hint in which direction to search for a possible solution so that a column {0,0} is added for empty intervals?

The attached VI contains 2 data arrays. In array 1 each subsequent interval contains at least 1 value (this works fine), in array 2 interval 3 (>=8 and <12) does not contain any value resulti
ng in the wrong output.
0 Kudos
Message 1 of 5
(3,761 Views)
Sander,

I'm 100% sure I could help you... if I knew what you were trying to do. The more I read your description, the less I understand, and since I don't really know what you're trying to do, I can't do much with your code.

It seems to me like your real problem is your ability to partition the original array into smaller arrays to do calculations on. If you can describe to me EXACTLY how the arrays are supposed to be partitioned, then I can help you out, even write you a VI that will do the trick, but I'm fuzzy on what's supposed to be happening.

Here's my understanding so far:
Everytime an element in the first column satisfies some value, it corresponding value in the second column is set aside to be used later.

Help me help you.
0 Kudos
Message 2 of 5
(3,761 Views)
In your "false" case you need to fill in the {0,0} missing elements. The only way that you hit the false case is if you come across a time stamp that is larger that the current interval. So, what you should do is put a loop in the false case that add the correct number of elements to "catch up" to the interval that will contain your next value (the one that cause the false case).

That is probably the easiest change.
0 Kudos
Message 3 of 5
(3,761 Views)
Victrick,

I am sorry to create so much fuzz, hopefully my explanation below is better to understand. So I hope you can help me.

Your understanding so far is correct: �Every time an element in the first column satisfies some value, it corresponding value in the second column is set aside in an array to be used later.�

The original array contains two columns; the first column contains a time stamp, the second column the actual measurement. I want to split this array into portions based on the values of the first column.
Initial it should check if the value in the first column starting at index 0 satisfies condition X and put the corresponding value from the second column in a split array, it should continue (continuing from index 1,2,�,n) to do so until
the value from the first column does not satisfy condition 1 anymore. Then it should calculate some statistics over the split array (summation, number of samples, etc).
After this the process should begin all over again starting to check if the value from the first column (starting at index n + 1) satisfies condition X +1 , and so on until there are no more values in the first column.

I managed to create a VI (attached to first post) that does all of the above without any problem as long as for all subsequent conditions at least one satisfying value from the first column can be found. E.g if for condition 10 no satisfying value from the first column can be found the first value from the next condition (in this case 11) is considered to belong to condition 10 and from that value the statistics are calculated. Instead it should consider that for condition 10 the value from the second column is 0.
0 Kudos
Message 4 of 5
(3,761 Views)
Hello,
I'm not sure why your vi didn't work, but I found it much easier to create one from scratch. I use two arrays, which are preallocated with the same number of categories as we would expect based upon the maximum value. Then you just check each column 0 in which category it belongs. Get the current number column0 and data of the category, add one for column0 and add the value as well and replace that in an array.
With your dataset it did the job.

Erik vH.
Applications Engineering
National Instruments
0 Kudos
Message 5 of 5
(3,761 Views)