![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/178554/image.png)
shift array to flat
조회 수: 1 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
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' ) ;
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/178554/image.png)
with
>> mean( detrend( unnamed ))
ans =
-3.9612e-18
>> mean( y )
ans =
-0.0011
댓글 수: 2
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 Center 및 File Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!