From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Taking row means in an array based on column values

Hi
 
I have a 2D array e.g 70 columns, 8 rows I want to take means of each column , but the rows which I take the means over dependent on the value in columns 1 and 2, so if the values in column one or two change I want to take the mean of all the rows in each column up to that point and then take a new mean for the rows until the value in column one or two change. I have tried several ways of doing this but am not getting anywhere. I attach the last attempt (I am referring to the part in the bottom left of the vi.). The idea was to have a for loop going through the rows of column one and two and returning true values when either changed (a shift register taking the last value through the loop) linking this boolean to a case structure where in the true event the index of the for loop (i.e. the row number is retuened and by taking through the case and a shift register through the for loop the previous index (row) through then then go through the original array by column and take subarray where the row number is the previous index and length the current index - previous index, but I am getting a bit confused now so if anybody has any ideas from scratch (for this part of the VI) that would be good too. Sorry I can't explain any better, any example vi suggestions also much appreciated cheers,
 
emily 
0 Kudos
Message 1 of 3
(2,252 Views)
Hello,

as far as I passed through your code, i found two possible mistakes:

1.) The most inner for-loop of your mean calculations does produce arrays with all elements the same value.  I guess this loop is maybe not nessessary, because it is not nessesary to walk though each cell/element. The Mean function handles Arrays.

2.) The use of the Shiftregisters for checking changes in row 1 and 2 is comparing neigbor elements in the array, i'm not shure,  if this was your goal.

To determine changes in row 1 and 2, you need a buffer which remembers somehow the old values of the rows 1 and 2. You can realize a buffer by using shiftregisters in the most outer for-loop or with a local or global variable.

You should also use own SubVIs, if possible, to keep your code more readable and keep a better overview.
I recommend you to read the "LabVIEW developer Guidelines", the include very helpfull tipps.

best regards,
Karlos
 
0 Kudos
Message 2 of 3
(2,247 Views)
Your description is not entirely clear to me. Do you want to take the average of multiple colums if they have the same values is colums 1&2? Should the values in column 1&2 be part of the average or are they just tags?
 
It would be better if you could attach a VI that contains typical sample data (run it with your data and in case the result is wrong, manually edit the indicator to contain the expected data. Now select Edit..make current values default. Now save it and attach it.
0 Kudos
Message 3 of 3
(2,240 Views)