LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How would I add the rows of a 640 x 240 2D array together? I mean , the elements of row 1 to the element of row 2 and so on. I want to end up with a 1 d array of 640 elements in which each element is the sum of the other 240 elements in the rows.

For explaination , like this
1 1 1 1 1 1 1 ....... to 640
+2 2 2 2 2 2 2 .......
+3 3 3 3 3 3 3 .......
=6 6 6 6 6 6 6 ....... this is the final 1D array of summed elements.
0 Kudos
Message 1 of 7
(3,291 Views)
Hope this helps

Denis Jolivet

"Big K" wrote in message
news:50650000000800000023360000-1007855737000@exchange.ni.com...
> How would I add the rows of a 640 x 240 2D array together? I mean ,
> the elements of row 1 to the element of row 2 and so on. I want to end
> up with a 1 d array of 640 elements in which each element is the sum
> of the other 240 elements in the rows.
>
> For explaination , like this
> 1 1 1 1 1 1 1 ....... to 640
> +2 2 2 2 2 2 2 .......
> +3 3 3 3 3 3 3 .......
> =6 6 6 6 6 6 6 ....... this is the final 1D array of summed elements.



[Attachment Untitled.vi, see below]
0 Kudos
Message 2 of 7
(3,291 Views)
> How would I add the rows of a 640 x 240 2D array together? I mean ,
> the elements of row 1 to the element of row 2 and so on. I want to end
> up with a 1 d array of 640 elements in which each element is the sum
> of the other 240 elements in the rows.
>
> For explaination , like this
> 1 1 1 1 1 1 1 ....... to 640
> +2 2 2 2 2 2 2 .......
> +3 3 3 3 3 3 3 .......
> =6 6 6 6 6 6 6 ....... this is the final 1D array of summed elements.
>

If you drop a For loop and wire the 2D array to the loop, it will
automatically index off the rows the way you need them. To accumulate
the values, you want to add each row to a 1D array that recurculates
through the loop.

To do this, initialize a 1D array constant full of zeroes to the width
of the 2D array. Add a
shift register to the For loop by popping up on
the edge. Wire the 1D constant to the shift register, and inside the
loop add the two 1D arrays together with a plus node. Wire the result
to the right shift register. The answer will come out of the right
shift register.

If the width of the array isn't fixed, use an initialize array instead.

Greg McKaskle
0 Kudos
Message 3 of 7
(3,291 Views)
Ewwww. Drop a for loop yes, but just use a "Sum Array Elements" inside the
loop and auto-index on in and out. No shift registers or preinit required.

"Greg McKaskle" wrote in message
news:3C217418.9030507@austin.rr.com...

> If you drop a For loop and wire the 2D array to the loop, it will
> automatically index off the rows the way you need them. To accumulate
> the values, you want to add each row to a 1D array that recurculates
> through the loop.
>
> To do this, initialize a 1D array constant full of zeroes to the width
> of the 2D array. Add a shift register to the For loop by popping up on
> the edge. Wire the 1D constant to the shift register, and inside the
> loop add the two 1D arrays together with a plus node. Wi
re the result
> to the right shift register. The answer will come out of the right
> shift register.
>
> If the width of the array isn't fixed, use an initialize array instead.
>
> Greg McKaskle
>
0 Kudos
Message 4 of 7
(3,291 Views)
> Ewwww. Drop a for loop yes, but just use a "Sum Array Elements" inside the
> loop and auto-index on in and out. No shift registers or preinit required.
>


That will work too, but I think you will need to transpose the 2D array
first. The autoindex will take out rows and the sumation will sum the
elements in the row rather than a column. Either will work.

Greg McKaskle
0 Kudos
Message 6 of 7
(3,291 Views)
Here is one way of doing it:

Transpose your array using the Transpose 2D array function, feed the resulting array to a For loop, and use the function Add Array Elements inside the For loop. This will give you your resulting 1D array.

I attached a VI that does just this. I hope this helps. /Mikael Garcia
0 Kudos
Message 5 of 7
(3,291 Views)