LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Subtract previous value from value in a large 1d array

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!

0 Kudos
Message 1 of 5
(4,036 Views)

Rotate the array by ine element and then subtract from the original.

 

Lynn

Message 2 of 5
(4,033 Views)

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.

 

 

0 Kudos
Message 3 of 5
(4,013 Views)

Here are a few simple possibilities, there are many more. All give the same result.

 

Message 4 of 5
(3,998 Views)

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

Message 5 of 5
(3,962 Views)