How do I center my time-history plot at zero using code

조회 수: 7 (최근 30일)
Joshua Castellanos
Joshua Castellanos 2021년 7월 21일
댓글: Scott MacKenzie 2021년 7월 21일
Hello all,
How can I make the plots of each time-history to be centered at zero using code? I usually manually add or substract the required amount from my data. As-per the example below. I wish to automate the centering of my plots.
Original code :
plot(t,x,t,x2,'r')
Revised Code (not the best solution)
plot(t,x-0.038,t,x2-0.003,'r')
Original:
Revised:
Thank you in advance

채택된 답변

Scott MacKenzie
Scott MacKenzie 2021년 7월 21일
편집: Scott MacKenzie 2021년 7월 21일
Is the offset you are subtracting the mean of the values in the corresponding arrays? If so, just subtract the means:
plot(t,x-mean(x),t,x2-mean(x2),'r')
As above is a tad better than manually inserting the means as magic numbers.
  댓글 수: 2
Joshua Castellanos
Joshua Castellanos 2021년 7월 21일
This is exactly what I needed. Thank you very much.
Scott MacKenzie
Scott MacKenzie 2021년 7월 21일
@Joshua Castellanos You're welcome. Glad to help. Good luck.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matched Filter and Ambiguity Function에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by