# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution

## how to subtract two (uint16)1D array of same size

I need to subtract two (uint16) 1D array of same size. with folowing output...

x - y = result(EXPECTED)

5 - 2 = 3

4 - 0 = 4

0 - 4 = 0

2 - 3 = 0

If difference is less than zero value should be zero. Right now, if I use numeric subtraction...i get ....

x - y = result(OBSERVED)

5 - 2 = 3

4 - 0 = 4

0 - 4 = 4

2 - 3 = 1

Thank You

Message 1 of 5
(597 Views)
Solution
Accepted by topic author rajxabc
08-27-2015 04:09 PM

## Re: how to subtract two (uint16)1D array of same size

Hello rajxabc,

I'm not sure why you expect unsigned integer math to produce a 0 in the scenario you show below.  The U16 will actually wrap past 0.

so,

0 - 1 = 65535

0 - 2 = 65534

0 - 3 = 65533

If you want to change the standard behavior of unsigned integer math, you'll have to create a special algorithm to produce this, something like:

There's a number of ways you could accomplish this but at the end of the day, I'm not sure I would label any of them "expected".

Message 2 of 5
(588 Views)

## Re: how to subtract two (uint16)1D array of same size

Your soultion is correct. Perhaps i was asking wrong question because i am still not able to acomplish what i wanted to do.

Kindly see attached block diagram.

incomming data is accumulated added values on each interval. (i dont have seperate access to new incomming values)

So, what i am trying to do is to , substract new array from last observed array .

for that i am using global array initialised with zero. is there a way to do that.

before i tried shift register, but on each loop my array was initialised to zeros.

Can you help me here . or i have to ask new question ?

I am accepting the previous answere.

Message 3 of 5
(574 Views)

## Re: how to subtract two (uint16)1D array of same size

Hi raj,

do you see all the red dots in your VI?

Why do you have a "0" constant as DBL instead of using an integer datatype as shown before?

Why don't you use a feedback node instead of globals?

Attach the real VI...

Best regards,
GerdW
CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 (+ LV2016 sometimes) on Win7+cRIO
Kudos are welcome

Message 4 of 5
(560 Views)

## Re: how to subtract two (uint16)1D array of same size

i tried to use feedback node, but it all got more confusing.

attached is vi file I am trying to modify for my need. I dont know LV at all.

The Idea is to save subtracted array as they come.

Array Xn - Xn-1 --> save to csv