From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Subtracting Arrays

Solved!
Go to solution

Hi Everybody,

 

I'm having a little bit of trouble with my code. I'm attempting to subtract an array of spectra (background data: 1 column x 2048 rows) from an array of aqcuired spectra (56 columns x 2048 rows). 

 

I've been attempting to subtract the 1 column array from each column in the bigger array, but I've had no luck. Does anybody have any tips? I want the output array to still be 56 columns x 2048 rows.

 

Small theoretical example:

 

Background Array:

1 2 1 2 3

 

Big Array: 

1 2 3 4 5

2 2 2 2 2

4 3 2 5 1

5 6 7 6 5

9 8 9 8 9

 

End Array:

0 1 2 3 4

0 0 0 0 0

3 2 1 4 0

3 4 5 4 3

6 5 6 5 6

 

Thank you

 

0 Kudos
Message 1 of 6
(5,419 Views)
Solution
Accepted by PoorCollegeStudent

What do you know about arrays and how LabVIEW handles them?  Do you know how arrays work with FOR loops?  If you have a 2D array, and I say "A For loop will give you the rows, one at a time", and you want to do the columns one at a time, can you think of an array operation that will exchange rows and columns so you can use the For loop to do columns, instead?

 

Put some of these ideas down in a Block Diagram, test it out, see if it works, and if it doesn't, post the code and ask for help.

 

Bob Schor

Message 2 of 6
(5,410 Views)

Thank you for the tip! After some fiddling around, I found out that the data I was reading was a 2 dimmensional array, so I had to make that into a 1 dimmensional array to work.

 

Thank you!

0 Kudos
Message 3 of 6
(5,395 Views)

Array.png

 

No need to change the dimensions of the array, if that is what you were implying.

 

0 Kudos
Message 4 of 6
(5,379 Views)

Transposing the array, and using autoindexing on the 2-D array subtracting the 1-D array.   Then transposing the result is a whole lot less code.

0 Kudos
Message 5 of 6
(5,353 Views)

Quite true.

 

However, I do not know whether it has changed in LabVIEW 2014, but transposing an array made a copy in older versions. For big arrays it was an expensive memory option for a slightly smaller ampunt of code. For small arrays, like the example here, I wholeheartedly agree with you.

 

Cheers,

mcduff

0 Kudos
Message 6 of 6
(5,320 Views)