10-28-2009 06:37 AM
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.
10-28-2009 06:53 AM
Can you post a screenshot or a picture of your problem. I didn't understand your sentence.
Mathan
10-28-2009 07:01 AM
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.
10-28-2009 07:03 AM
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.
10-28-2009 07:22 AM - edited 10-28-2009 07:23 AM
Hi Guohong,
yes, you can't transpose an 1D array 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!
10-28-2009 07:30 AM - edited 10-28-2009 07:39 AM
Here is an example with a switch for row or column averaging. The TRUE case of the case statement contains a Transpose 2D Array.
If you want to average the whole array, you can do this easily by using Reshape Array, then Mean.vi. Here is that example.
10-28-2009 07:45 AM
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.
10-28-2009 07:51 AM
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...)
10-28-2009 09:01 AM
Hi GerdW
works, thanks a lot!
GH