LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to calculate the mean of a section of an array?

hello
 
i have an array of 26 elements.some sections of it are all zeros and some others are numbered. i want to be able to find the mean of the numbered sections and replace those values. an example 0,0,0,0,0,2,3,4,6,5,7,8,0,0,0,9,8,7,4,0,0,0.....and i want to be able to get it as in 0,0,0,0,0,5,5,5,5,5,5,5,0,0,0,7,7,7,7,0,0,0....
 
i know you can do it "kinda" manually with the array subset vi. but i want to find a more correct way to do this.can anybody help me on this?
 
i have attached the array with the actual numbers if it will save you 2 minutes of your time by generating another one
 
cheers
0 Kudos
Message 1 of 19
(4,064 Views)
Hello Madgreek,
      Thank you for the test-data!  I doubt this (attached) is the "more correct way", but it seems to do what you asked (without using Array Subset. Smiley Wink - )
 
Hope it helps!
0 Kudos
Message 2 of 19
(4,049 Views)
0 Kudos
Message 3 of 19
(4,045 Views)
Dr Ivel hello
first of all thank you for your time and effort
is it possible to save whatever you did in labview 7.0 and repost it again plz?i dont currently have 7.1
 
regards
madgreek
0 Kudos
Message 4 of 19
(4,041 Views)
its ok i got it.
 
thanks alot again for your help.its exactly what i needed
 
regards
 
madgreek
0 Kudos
Message 5 of 19
(4,013 Views)
Dr Ivel
 
i tried to comprehend what you have been doing in the vi you sent to me and i can surely say i am officially lost 🙂
is it possible to give me a brief description about it?
i know that you are passing the zeroes without doing anything on them....when values start coming in you add them somehow and u estimate their mean...fine up to now...its just it is somehow difficult for me to see that looking at the whole vi.....im looking for just few pointers there about the programming part
 
kind regards
madgreek
0 Kudos
Message 6 of 19
(4,006 Views)
Here's an alternative solution (LV 8.0)  that uses fewer shift registers and has only one case structure. Se if it makes more sense to you.
 
 
Notice that Dr.Ivels solution is incorrect if the array starts with a nonzero segment (e.g. 4,5,0,0,0,0,...), or ends with a nonzero segment (e.g. ...0,0,0,7,8). It would need to be tweaked a bit for correct operations under these conditions.
 
Please verify correct operations, I haven't fully tested my solution either with pathological data, but it seems to work correctly in the above cases. 🙂

Message Edited by altenbach on 02-14-2007 04:10 PM

Download All
Message 7 of 19
(3,996 Views)

Altenbach

thank you very much about your suggestions and effort...i didnt expect anyone to bother going through the post again after it was basically answered....although my arrays never have zeroes at the beginning or end , you were absolutely correct about it  and its good to have that in mind.

regards

madgreek

0 Kudos
Message 8 of 19
(3,983 Views)

Here's a quick explanation how my code works

  1. Seach for the next zero in the input array
  2. If the next zero is one index higher, we just keep doing that and nothing else.
  3. If the next zero is more than one index number higher, we take the subarray from the current position to the position before the just found next zero, average it, and create an array of same size containg the average at each element. The result is written back to the same location where we just grabbed the subarray.
  4. there is some extra code to correctly deal with the end of the input array and stop the loop, but that's about it.

makes sense?

(There are many variations that might be even faster. For example you could do an "=0" to create a boolean array, then alternately seach for TRUE and FALSE, to get the segment boudary indices directly. Right now we are traversing the dead spots in first gear, one element at a time. ;))

0 Kudos
Message 9 of 19
(3,978 Views)
yes it makes sense....
thanks again for everything
 
Madgreek
0 Kudos
Message 10 of 19
(3,976 Views)