03-27-2013 10:11 AM
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
Solved! Go to Solution.
03-27-2013 10:16 AM
03-27-2013 10:24 AM
Searched where? If you need to manipulate arrays why not just use the functions in the ARRAY palette?
03-27-2013 10:53 AM
I hav searched for "ARRAY INDEX VALUE MANIPULATING FUNCTION" not manipulate array value...
03-28-2013 09:50 AM
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:
This way uses Array Size and Index Array VIs. Gerd's way is better.
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. LabVIEW provides basic functions. You have to put them together to create more specific functions.
02-08-2016 06:27 PM
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.
02-08-2016 06:41 PM - edited 02-09-2016 09:45 AM
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):
02-08-2016 06:51 PM
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.
02-08-2016 07:11 PM
02-08-2016 07:27 PM
Actually Niquist's post was just acting on the original array N times with looking at elements 0 and 1.