How to add max and min data label of plot in matlab with help of annotation?
조회 수: 88 (최근 30일)
이전 댓글 표시
I want label max and min data label with use of annotation on gh bottom,middle and top plot to show the values of max and min. How to use text function here?
gh=readtable("number4.CSV")
gh = gh(gh.Time <= 4900 | ismissing(gh.Time),:);
plot(gh.Time,gh.bottom,gh.Time,gh.middle,gh.Time,gh.top)
xlim("auto")
ylim("auto")
grid on
xlim([190 1633])
ylim([23 854])
title(" cube sheet")
xlabel("Sampling rate (Hz)")
ylabel("sheet temperature (C)")
legend(["Bottom","Middle","Top"])
xy=max(gh.bottom)
xy1=min(gh.bottom)
xy2=max(gh.middle)
xy3=max(gh.top)
xy4=min(gh.middle)
xy5=min(gh.top)
댓글 수: 0
답변 (1개)
Cris LaPierre
2022년 8월 6일
편집: Cris LaPierre
2022년 8월 6일
You limit you view of the data in the figure by using xlim, but not your search for max and min values. This does mean some of the max/min values may not be within the visible range of your data.
One your restrict the range of your search for max/min values, you will likely be interested in the this syntax. The 2nd output is the index of the found value. You can use this to index your time variable, allowing you to get the (x,y) data needed to plot.
EDIT: Question was updated. Adding code to label points using text.
file = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/1089860/number4.CSV';
gh=readtable(file)
gh = gh(gh.Time <= 4900,:);
plot(gh,"Time",["bottom","middle","top"])
grid on
title(" cube sheet")
xlabel("Sampling rate (Hz)")
ylabel("sheet temperature (C)")
[mny,mni]=min(gh{:,["bottom","middle","top"]});
[mxy,mxi]=max(gh{:,["bottom","middle","top"]});
hold on
plot(gh.Time(mni),mny,'^')
plot(gh.Time(mxi),mxy,'*')
hold off
text(gh.Time(mni),mny,'min')
text(gh.Time(mxi),mxy,'max')
legend(["Bottom","Middle","Top"])
댓글 수: 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!