07-02-2013 04:43 PM
Sorry I thouhgt it would be kind of relevant to the previous post!
My vi is pretty simple, it generates a random 2d array, and then takes the mean of the means.( So the mean of the means of each row)
The array "appended array 4" ( highlighted in green)n is the one that is being passed by the shift register.I dont understand why there is an extra line of zero?
Thanks!!
07-02-2013 05:38 PM - edited 07-02-2013 05:41 PM
You build a 2D array with a 1D array and a 2D array. Since the 1D array is initially empty, it will be padded with the correct number of zeroes and thus you get a row of zeroes.
It is a little hard to figure out what you are trying to do. The code seems way too convoluted.
Why do you even have shift registers?
07-02-2013 06:01 PM - edited 07-02-2013 06:05 PM
To generate a 2D array, then taking the mean of each row, then the mean of these means takes very little code. Here's what you could do.
(also note that your random integer gererator is highly biased, because 0 and 5 only occur at about 50% of the frequency of the other numbers. You need to multiply by 6 and round to -infinity to get even probabilities.)
07-03-2013 09:54 AM - edited 07-03-2013 09:55 AM
thanks for the reply!
The reason I have shift registers is because I need to save all the values in the random array and the mean array.
This is ultimately what Im trying to do:
I want to take the mean of the first n1 points(generated by the random array) on the first iteration. On the next iteration, I need to take the mean of all the points I have so far, so from 0 to n2. On the next iteration I would take the mean of all the exising points so far, so 0 to n3( 0 < n1<n2<n3) and so on. So thats why I used shift registers to save these values each time.
I hope this makes my code a bit more clear!
07-03-2013 10:20 AM - edited 07-03-2013 10:20 AM
developer001 wrote:I want to take the mean of the first n1 points(generated by the random array) on the first iteration. On the next iteration, I need to take the mean of all the points I have so far, so from 0 to n2. On the next iteration I would take the mean of all the exising points so far, so 0 to n3( 0 < n1<n2<n3) and so on. So thats why I used shift registers to save these values each time.
I hope this makes my code a bit more clear!
No, it is not clear.
Why do you generate a 2D random array at all. 0..n1, 0..n2, etc. all look pretty 1D to me, but maybe I don't quite understand your nomenclature.
07-03-2013 10:28 AM
The 2D random array will ultimately be my input data (right now I am just trying to simulate the situation).
So as I receive data (in the form of a 2d array) at a constant speed, I want to take the mean of the values I have so far.
So the first time I would have a mxn array as input, I take the mean and get a mx1 array of means.
The second time I will have a new axb input data (m=a and n=b), this time I will take the mean of all the points I have so far ( the m x (n+b) array) and get a new mx1 array of means.
Basically I need to take the mean of all the available points at any given time.
07-03-2013 11:36 AM
So you want a moving average? Then why calculate the mean of all values each time? The average will always be:
Mean-mean/num of measurements + new value/num of measurements.
Although your number of measurements is probably small and you can recalculate it each time. 🙂
/Y
07-03-2013 12:42 PM - edited 07-03-2013 12:43 PM
Well, this seems like a pretty useless exercise, but of you want to add new rows to a 2D array, you need to initialize the shift register with a 2D array and use built array in concatenate mode.
Here is a quick example that appends a new 2D array to an existing 2D array and does the mean of rows and overall mean. (Of course you'll run out of memory and the task gets harded and harder with each iteration so you need to modify for your purpose. Still, this should get you started).
07-04-2013 02:23 PM
Thanks! It was very helpful
But as you mentioned it eventually runs out of memory. I know that build array is the cause, so can i use "replace aray subset" instead? I tried butI cou;dn't replace an entire 2d array at once with the correct index.
Ive modified the program, so now the output array does exactly what it should do, so now I just need to fix the memory issue.
thanks in advance!!
07-04-2013 02:57 PM - edited 07-04-2013 02:57 PM
Your code is still incredibly convoluted: