How to add max and min data label of plot in matlab with help of annotation?
62 ビュー (過去 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!