shift array to flat
1 view (last 30 days)
i have a 142 element array that generates a curve (attached). when a line is drawn from end to end the line is at a certain (unknown) slope. how could i adjust the values in the array so that when plotted and a line drawn from end to end of the curve, the slope is 0?
picture and array is attached.
Cedric Wannaz on 7 Oct 2017
Edited: Cedric Wannaz on 7 Oct 2017
plot( unnamed, 'b' ) ;
hold on ; grid on ;
x = (1 : length(unnamed)).' - 1 ;
slope = (unnamed(end) - unnamed(1)) / (length(unnamed) - 1) ;
y = unnamed - (unnamed(1) + x * slope) ;
plot( y, 'g' ) ;
but we often need something else :
plot( detrend( unnamed ), 'r' ) ;
>> mean( detrend( unnamed ))
>> mean( y )