How to add max and min data label of plot in matlab with help of annotation?

62 ビュー (過去 30 日間)
Matthew Worker
Matthew Worker 2022 年 8 月 6 日
編集済み: Cris LaPierre 2022 年 8 月 6 日
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)

回答 (1 件)

Cris LaPierre
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 = 5900×4 table
Time bottom middle top ____ ______ ______ ______ 0 43.195 41.69 32.371 1 43.19 41.693 32.371 2 43.186 41.7 32.371 3 43.187 41.704 32.366 4 43.186 41.714 32.367 5 43.191 41.717 32.364 6 43.19 41.721 32.364 7 43.191 41.727 32.362 8 43.188 41.732 32.361 9 43.187 41.737 32.36 10 43.191 41.745 32.36 11 43.194 41.752 32.358 12 43.192 41.755 32.358 13 43.194 41.76 32.354 14 43.197 41.764 32.356 15 43.199 41.774 32.354
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"])

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by