LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

difference between adjacent array values..

Solved!
Go to solution

hi,

   I want to subtract adjacent elements in an array. I mean 1st element- 2nd element, 2-3,3-4,4-5 and so on.. i hav searchd for array index manipulating fn. but dint get.. help me. thanx in advance

0 Kudos
Message 1 of 15
(14,205 Views)

Hi n,

 

easy as this:

check.png

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 15
(14,199 Views)

Searched where?  If you need to manipulate arrays why not just use the functions in the ARRAY palette? 

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019 - Unfortunately now moving back to C#, .NET, Python due to forced change to subscription model by NI. 8^{
Message 3 of 15
(14,194 Views)

I hav searched for "ARRAY INDEX VALUE MANIPULATING FUNCTION" not manipulate array value... 

0 Kudos
Message 4 of 15
(14,184 Views)

I'm just saying that there's no need to search at all.  Just use the built-in array functions to do what you need.  They are found in the  array palette.  Here is another (more basic) way to do what you want:

Array Subtraction.png

 

This way uses Array Size and Index Array VIs.  Gerd's way is better. Smiley Wink

If you're looking for a LabVIEW function that outputs the difference between adjacent values in an array I'm afraid you're out of luck. Smiley Sad  LabVIEW provides basic functions.  You have to put them together to create more specific functions. 

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019 - Unfortunately now moving back to C#, .NET, Python due to forced change to subscription model by NI. 8^{
0 Kudos
Message 5 of 15
(14,153 Views)

 

This is many years later, but this is the first post that comes up when you Google "labview diff adjacent elements", so I thought I would a) post the correct answer, since NIquist's is wrong, and the "Solved" answer is no longer visible; and b) vent on NIquist for being an insolent mocking **bleep** to the OP and then failing to post an answer that solves OP's problem. Way to go, NIquist, you are the epitome of the unsupportive smarter-than-thou community that exists on these LabVIEW boards. Someone must have really made your life miserable in middle school or something. Sorry that you feel like you have to take out your inadequacies on random strangers looking for coding help.

 

Anyways, OP wants something equivalent to the "diff" function in MATLAB, which takes an N-element 1D array and returns an N-1 element array, where the jth element of the output array is the result of subtracting the ith element from the i+1th element of the input array. A VI that does this is attached.

 

What NIquist's moronic program does is just contunally find the difference of the second and first elements of the input array. This is not what the OP wanted, yet NIquist found it necessary to first not answer OP's question, then mock OP's inability to make the program while subsequently failing to make the program himself. How supportive, NIquist. Thanks for your glowing contribution to this community.

 

 

Download All
Message 6 of 15
(12,753 Views)
Solution
Accepted by RavensFan

That looks like a very bad solution, just for the memory thrashing due to the constant resizing of data structures.

 

I don't know what Gerd's solution was, but it probably was as easy as the following (using "array subset", swap the input to the subtraction if desired):

 

Message 7 of 15
(12,738 Views)

Thank you altenbach, my solution was very bad and yours is much more elegant. Thank you also for not being condescending or arrogant about your correction.

0 Kudos
Message 8 of 15
(12,727 Views)
Also NIquist is a very respected member here. The only problem is a missing wire from [I] to the upper index terminal and a -1 going to N. Happens to all of us.
0 Kudos
Message 9 of 15
(12,705 Views)

Actually Niquist's post was just acting on the original array N times with looking at elements 0 and 1. 

0 Kudos
Message 10 of 15
(12,697 Views)