LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

adding two arrays together

I am trying to add two arrays together, it does not seem as if the arrays are broken up into more than one index. I have attached my code. If the array is broken up into indexes I would like to add each corresponding index, but I think the array is all in just one index and if so I was wondering how would I break it into indexes. Thanks

0 Kudos
Message 1 of 15
(16,748 Views)

First I have to ask, why are you taking a 2-D array, converting it to a dynamic data type, and the converting it to a 1-D array?  What is the meaning of th 1-D array vs. 2-D array?

0 Kudos
Message 2 of 15
(16,744 Views)

Since you are "transposing" and later work with 1D array, I assume you want to read the first column of the file.

 

Why do you need a sequence stacked 5 frames deep, local variables, 5 instances of the same boolean diagram constant and 5 path conststants of which some are identical??? 😮 None of this is needed!

 

 

All you need is probably something along the lines of the following picture, which probably does something similar to what you want. Still, we are probably still jumping through too many flaming hoops. Note that the execution order is uniquely defined by the wiring alone, no sequence needed! Can you take a step back and tell us what you are actually trying to achieve with all this? How many columns are in the file? Only one?

 

Message Edited by altenbach on 01-27-2009 04:02 PM
Message 3 of 15
(16,715 Views)
the data i am trying to record is from a laser that scans from lets say 0 to 5 and collects data at each integer(0,1,2,3,4,5). what i want to do is after 50 scans ,for example, i want to add the corresponding data taken at each integer. in other words each number 0-5 will have 50 data points and i want to add the 50 together for each integer, i don't want the sum of everything. in the end i want the sum of the data taken at the scan point 0, at the scan point 1, and so on. i thought using an array would allow me to do this. i was trying to record the data in a column, each column represents an integer (0-5). and i wanted to add the corresponding columns. sorry if this is a bit confusing. any help is appreciated.
0 Kudos
Message 4 of 15
(16,676 Views)

Assuming I understood your question correctly heres a solution:

This will make an array of the sum of each column.

Message Edited by Cory K on 01-28-2009 12:04 PM
Cory K
0 Kudos
Message 5 of 15
(16,662 Views)
One step simpler, you can replace the inner for loop and shift register with an Add Array Elements function from the numeric palette.
Message 6 of 15
(16,654 Views)

Ravens Fan wrote:
One step simpler, you can replace the inner for loop and shift register with an Add Array Elements function from the numeric palette.

 

There I go reinventing the wheel again, only bigger and clunkier

Cory K
0 Kudos
Message 7 of 15
(16,652 Views)

(Cory, your inner FOR loop can be replaced by "add array elements", an atomic operation. :))

 

You definitely don't need to do disk IO for any of this. All you probably need to do is buit a 2D array at the loop boundary, transpose, and sum the slices in a loop, e.g. as follows.

 

Modify as needed. Let me know if anything is not clear.

 

Message Edited by altenbach on 01-28-2009 10:21 AM
Message 8 of 15
(16,650 Views)

altenbach wrote:

(Cory, your inner FOR loop can be replaced by "add array elements", an atomic operation. :))


For some reason, once I start thinking about something, I automatically start coding without checking if there is a function that already does the desired task. That would probably be a good thing to start doing.

Cory K
0 Kudos
Message 9 of 15
(16,641 Views)

Cory K wrote:

For some reason, once I start thinking about something, I automatically start coding without checking if there is a function that already does the desired task. That would probably be a good thing to start doing.


Oh, I know how that works! 😄

 

At least you found a nice "in-place" solution. Some would have added things via value property nodes. 😮

0 Kudos
Message 10 of 15
(16,635 Views)