06-21-2015 06:33 AM
I have data in a 1d array (grabbed from csv file) and I need to generate a new 1d array that represents the difference between the previous value and the current value at each timepoint (ie, Ax1 minus Ax-1). I cannot find a LabView function to do this, so any assistance would be greatly appreciated. Cheers!
06-21-2015 06:34 AM
Rotate the array by ine element and then subtract from the original.
Lynn
06-21-2015 07:36 AM
Take the array subset starting from element 1 (i.e. without the first point) and subtract the original array. The result will have one element less as it should.
If the array is large, you can eliminate the extra array allocation by using a FOR loop with a shift register. it might be slower but use less memory. You need to benchmark to find out what performs better.
06-21-2015 07:55 AM - edited 06-21-2015 07:55 AM
Here are a few simple possibilities, there are many more. All give the same result.
06-21-2015 09:54 AM
For small arrays altenbach's sub 1 as shown above seems to be fastest. For arrays large enough (6E7 elements) to have memory allocation issues, sub2 does better. My benchmarking is only approximate but the trends seem clear. I also tried a few other methods than those shown but none matched the performance.
Lynn