LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

average in matrix in blocs of 10 columns

Solved!
Go to solution

Hello all,

I am a complete beginner with Labview and im working on a project that requires me to average the time in a 200 by 300 matrix. the rows are the location and columns the time.

I need to make an average for every 10 col. and then plot it.

so from 0 to 300 [columns] 1 to 10 = t1, 11 to 20= t2 etc

 

 I was told to do it with a double loop and been searching for examples on how to do that, because i will have to do so with a 200 x 20 000 matrix soon.

 

I could really use some help on this, so if anyone is up for it 🙂

 

 

0 Kudos
Message 1 of 8
(3,418 Views)

Hi,

 

I hope this helps you - nested loops are definitely the way to go for something like this.  Also, notice that I've used the replace array subset vi rather than build array.  Build array is very slow - something you'll really notice if you try to use it with a 20000 element array.  If you know the final size of your array (and you do in this application), it is much faster to initialize an array of the correct size and replace the individual elements.

 

Best of luck!

Jason

0 Kudos
Message 2 of 8
(3,400 Views)
Hi Jason thanx for that, but i only have version 8.5. is there a way for me to convert it?
0 Kudos
Message 3 of 8
(3,375 Views)
I *think* I've managed to resave it as an LV8.5 file.  Let me know if it works...
0 Kudos
Message 4 of 8
(3,367 Views)

yup it opens fine with ver.8.5

i see how it can be better\ faster to add values

 

but how do the loops work in principal? say for the inside loop if it goes from 1 to 10, while the "outside" loop goes from says 1 to 30, is each iteration of the outside loop going to progress after all iteration of the inside loop are done?

if i want the small loop to group 10 columns together then average it doing so sends it to the other loop where it goes into say t1`, then all the other iteration of the inside loop to create col 2, etc etc?

 

0 Kudos
Message 5 of 8
(3,341 Views)

OK - I think I see your problem.  It sounds like you are assuming that once the inside loop runs through its iterations one time, it's finished.  But with nested loops, the interior loop will execute a full set of iterations for every iteration of the outside loop.  Let's use your example where the inside loop goes from 1 to 10 and the outside goes from 1 to 30.  In that case, when you enter the outside loop in iteration 1, the inside loop will run 10 times.  Then the outside loop goes to iteration 2, and the inside runs another 10 times, etc. etc. until the outside loop completes all its iterations. 

 

I wasn't sure I understood the second question - Does this cover it?

 

 

0 Kudos
Message 6 of 8
(3,318 Views)

Thats sounds perfect, thats exactly what i meant.

 

but how do i make it to take the first 10 col then the next 10 cols? what boundries should i give the loops?

I `m also assuming that for the "outside" loops i need to have N= 30 to create 30 sets of 10columns ( for the time columns), right?

0 Kudos
Message 7 of 8
(3,313 Views)
Solution
Accepted by topic author abs(noob)

Take a look at the code I wrote for you - it'll do exactly what you want.  Notice that I never wired anything to the "N" in the outer loop.  If you run an array into a For loop, it will default to auto-index the array.  In other words, the loop will run for each element in the array.  If you look at where the array runs into the outer loop, you can see the wire goes from a 2d array double line to a 1d array single thick line.  That's the auto-index in action.

 

To get it to step through the columns, you need to wire up the "i" counters in the loops and run some math on them.  In the inner loop, I multiply the "i" by the average size, and feed it in to the array subset function as the starting index.  So for your case where average size = 10, while the inner loop is counting 0,1,2... my array subset is getting 0,10,20... as the starting index.  Throw the average size into the length input, and the array subset gives you exactly the chunks you want. 

Message 8 of 8
(3,299 Views)