09-13-2013 11:30 AM
@developer001 wrote:
Is there a simpler way to do this?
Your code is pure LabVIEW gibberish. Your inner FOR loop has absolutely no purpose.
Do you need to keep a seperate mean for each row, or do you just want the global mean of the 2D array?
To just keep the global sum and mean of a 2D array, here's what you could do.
09-13-2013 11:33 AM - edited 09-13-2013 11:37 AM
Well, your VI doesn't do the same as mine. Did you actually mean that you wanted to record the average of all 30 data points? I thought you needed the separate averages of the three sets of 10.
To get that, just take the mean of your new 2D array and add it to the previous result. Since the initial arrays are all the same size, it doesn't matter whether you take the mean first or add everything together first.
Or you could do the same thing I did, but do it with 2-D arrays, then calculate your mean of the second dimension. The commutative property (or is it the distributive property? Whatever.) of math operations is a wonderful thing (of course, I don't mean all math operations).
Then to get the overall average, just take the mean of your resulting 3-cell array.
(BTW, if you straighten out your wires and try not to go backwards, your VIs will be a lot easier to read.)
Cameron
09-13-2013 11:44 AM
@altenbach wrote:
@developer001 wrote:
Is there a simpler way to do this?
Your code is pure LabVIEW gibberish. Your inner FOR loop has absolutely no purpose.
I guess he didn't want it to be random over x, but x^2*10 ? I just used his "random generator" because it made no difference in what I was doing. I thought he wanted to see what was happening each step of the way to that global average.
Cameron
09-13-2013 11:44 AM
Yes I need to keep a separate mean for each row, as they are data for different channels.
09-13-2013 11:54 AM
Ok I think I need to clear up exactly what I want to do:
Each 3x10 array is a data block.
Each row is a different channel (3 channels), so I need to take the mean of each row separately. So the mean array would be 3x1.
I will be receiving 3x10 blocks of data continously, and I will need to take the mean contiously.
Sorry guys if I confused you!
09-13-2013 11:54 AM - edited 09-13-2013 11:57 AM
09-13-2013 12:45 PM - edited 09-13-2013 12:47 PM
Hey, alterbach, I think your solution is identical to mine, although I did not put the indexing into a for loop (now attached). In G, is there any difference in performance between wiring the function expressed for each index and using a for loop? I don't know any of the internals here.
Cameron
09-13-2013 12:52 PM
Thanks guys it works just the way it should!!
09-13-2013 02:02 PM - edited 09-13-2013 02:06 PM
@camerond wrote:
Hey, alterbach, I think your solution is identical to mine, although I did not put the indexing into a for loop (now attached). In G, is there any difference in performance between wiring the function expressed for each index and using a for loop? I don't know any of the internals here.
You should always use autoindexing. Most likely there is no performance difference and the compiler will generate identical code. However, of you don't use autoidenxing, the diagram is more cluttered and there are more places for bugs to hide or for mistakes to occur. What if you wire to the other index by accident? Your code is also broken, because N is not wired.
Your code is not the same, because it is less scalable. For example, if there is a need to change the number of rows, you need to make changes in several places (initiaize array, generate random array), and if you miss one place, the thing will not work right. In my code, only a single change needs to be made. Much easier to keep things consistent.
My code automatically adapts to 2D arrays of any size.
09-13-2013 02:27 PM
Whoops, I got it. Didn't realize that I had lost the autoindexing when I modified the code from his requirement of a fixed 3 x X array to what should have been a general solution. Just popped that out and didn't look back, didn't even notice it broke the arrow. Funny, because I always look back. Oh, well, I guess Friday the 13th struck me after all.
Cameron