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: 

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

Solved!
Go to solution

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 

0 Kudos
Message 1 of 5
(2,919 Views)
Solution
Accepted by topic author rajxabc

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

 

 

un

 

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:

 

Untitled.png

 

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".

0 Kudos
Message 2 of 5
(2,910 Views)

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.

 

0 Kudos
Message 3 of 5
(2,896 Views)

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


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 5
(2,882 Views)

Hi GradW,

 

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

Any suggestions would be helpfull. 

Thank you 

0 Kudos
Message 5 of 5
(2,868 Views)