LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

average values of a 2-D array

Hi folks,

quite simple question, just want a simple solution. I've got a 2-D x*y array, need the average value of all the y volume numbers, which means eventually I will have a x*1 1-D array. Is there any simple solution instead of 2 loops? Cheers. 

0 Kudos
Message 1 of 9
(4,225 Views)

Can you post a screenshot or a picture of your problem. I didn't understand your sentence.

 

Mathan

0 Kudos
Message 2 of 9
(4,220 Views)

It can be done in a single loop.

 

Within a For loop you can index each row or column (depending on what you want your average to be).

Then use the function (Sigma symbol) to Sum all array elements and divide by the number of elements (also a function for that in the array palette). Wire each of the averages to the ouput tunnel of the For Loop which will result into a 1D array of averages.

 

 

0 Kudos
Message 3 of 9
(4,217 Views)

sorry. for example here is array

n11,n12,n13,...,n1x;

n21,n22,n23,...,n2x;

......

ny1,ny2,ny3,...,nyx.

I need the average of all the columns, so I will have then:

Av1,Av2,Av3,...,Avx.

in which Avx is the average of n1x,n2x,...,nyx.

I used one auto-indexed for loop to do that, but before I have to transpose the 2-D array, and the result is a 1-D volumn array which I can't transpose it to a row.

hope it's clear.

0 Kudos
Message 4 of 9
(4,216 Views)

Hi Guohong,

 

yes, you can't transpose an 1D array Smiley Wink But is it important to have a direction for a vector (row or column)? (Direction is just UI cosmetics.)

 

LabView doesn't know of a difference between a row vector or a column vector - it's just an 1D array... So your solution was ok!

Message Edited by GerdW on 10-28-2009 01:23 PM
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 9
(4,209 Views)

Here is an example with a switch for row or column averaging.  The TRUE case of the case statement contains a Transpose 2D Array.

 

RowColumnAveraging.png

 

If you want to average the whole array, you can do this easily by using Reshape Array, then Mean.vi.   Here is that example.

 

MeanOf2DArray.png

 

 

Message Edited by DFGray on 10-28-2009 07:39 AM
0 Kudos
Message 6 of 9
(4,203 Views)

Hi GerdW,

well, the direction IS quite important. look, this 1-D array is for 1 test, I will have to put all the tests results in one file. If I simply use the "insert into array", it will eventually give me a long long 1-D array but not a 2-D array. My current solution is to transfer the 1-D array to string and combine all the strings, which works but a little hassle.

0 Kudos
Message 7 of 9
(4,194 Views)

Hi Guohong,

 

that is not clear to me. An 1D array is just a series of numbers. And you never spoke of resulting 2D arrays before.

 

So you want to collect several 1D arrays from multiple tests in a 2d array. Ok. Why not use "build array" (which is what you want to do) or - even better - autoindexing of a for loop? Why do you use "insert into array"? (This function is one of the most wrong used ones in LV...)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 9
(4,179 Views)

Hi GerdW

works, thanks a lot!

GH

0 Kudos
Message 9 of 9
(4,162 Views)