LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

shift register values

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!!Smiley Happy

0 Kudos
Message 11 of 22
(1,617 Views)

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?

0 Kudos
Message 12 of 22
(1,613 Views)

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.)

 

 

0 Kudos
Message 13 of 22
(1,609 Views)

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!Smiley Happy

0 Kudos
Message 14 of 22
(1,577 Views)

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!Smiley Happy


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.

0 Kudos
Message 15 of 22
(1,559 Views)

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.

0 Kudos
Message 16 of 22
(1,555 Views)

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

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 17 of 22
(1,518 Views)

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).

 

0 Kudos
Message 18 of 22
(1,504 Views)

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!!

0 Kudos
Message 19 of 22
(1,483 Views)

Your code is still incredibly convoluted:

  • The shift register with the 1D array is never used, so why is it there?
  • Why do you constantly transpose? You definitely should add rows like in my example. Adding columns is very expensive becaue the values are not adjacent in memory.
  • You tap into the shift register value before the build array node, thus your analysis lags one iteration behind.
  • What's the point of the lower shift register? Its value is never used.
  • You will run out of memory no matter what, because your data structures grow without bounds.
  • Why don't you start with the code I showed you, it is much more streamlined?
0 Kudos
Message 20 of 22
(1,471 Views)