How do I name the trendline in the legend? Also, how can I get the trend line equation on the plot?
조회 수: 9 (최근 30일)
이전 댓글 표시
답변 (2개)
Bjorn Gustavsson
2019년 3월 19일
Maybe:
if c(2) > 0
equation_string = sprintf('%4.3f x + %4.3f',c(1),c(2));
elseif c(2) < 0
equation_string = sprintf('%4.3f x - %4.3f',c(1),abs(c(2)));
else
equation_string = sprintf('%4.3f x',c(1));
end
legend('Data',['Best linear fit: ',equation_string])
text(12,43,equation_string)
HTH
댓글 수: 0
Star Strider
2019년 3월 19일
It is not possible to run an image of your code.
Try this:
Voltage = linspace(10.45, -1.4, 8);
GaugePressure = linspace(3353, 0, 8);
c = polyfit(Voltage, GaugePressure, 1);
y_est = polyval(c, Voltage);
figure
plot(Voltage, GaugePressure, '--bs')
hold on
plot(Voltage, y_est, 'r--')
hold off
legend('Data', 'TrendLine', 'Location','best')
Add your title and axis label calls.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!