shift array to flat

5 次查看(过去 30 天)
Munsell Randall
Munsell Randall 2017-10-7
编辑: Cedric 2017-10-7
hello,
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
Cedric 2017-10-7
编辑:Cedric 2017-10-7
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' ) ;
with
>> mean( detrend( unnamed ))
ans =
-3.9612e-18
>> mean( y )
ans =
-0.0011
  2 个评论
Munsell Randall
Munsell Randall 2017-10-7
whats the purpose of the detrend?
also, what i really wanted to do was bring the lowest side of the plot level with the highest. how would i do that?
Cedric
Cedric 2017-10-7
编辑:Cedric 2017-10-7
doc detrend : removes linear trend.
What I understood from your question was that you wanted the green line on my plot, which is the curve shifted up based on the value defined by the black line. If it is correct, this is what I compute/define as y.
Thinking a bit more about it, you may want
y = unnamed - x * slope ;
if you want the first value to match.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Curve Fitting Toolbox 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by