How can I identify only the first or first two local minima from "islocalmin" and then display it in a table on a plot?

27 ビュー (過去 30 日間)
I have plots that look like the example below. There are several curves that look like horizontal waves. For each one, there is a corresponding curve that goes from ~x=0, y=0 to x=8, y=5.
I can use "islocal min" (see https://www.mathworks.com/help/matlab/ref/islocalmin.html) to find the local minima on the horizontal waves (as shown for one example--the orange dashed curve near the bottom of the plot). Here's how I do it:
yyaxis left
plot(VarName1,VarName2,'Color',[0.4660 0.6740 0.1880],'Linestyle','-','Linewidth', 2.3,'DisplayName','Example 1 horizontal wavy curve);
yyaxis right
plot(VarName1,VarName3,'Color',[0.4660 0.6740 0.1880],'Linestyle','-','Linewidth', 1.0,'Example 1 diagonal curve'); hold on
TF = islocalmin(VarName2);
plot(VarName1,VarName2,VarName1(TF),VarName2(TF),'r*')
What I want to do now is:
  1. Only show the first local minimum (right now I show all of them).
  2. Find the y value on the right-hand axis of the corresponding diagonal orange curve immediately above.
  3. Display that value on a table in or below the figure for all of the curves, with the curve names. I know how to annotate the plot at a point, but don't want to do this because I have so many curves it would get confusing.
I can't figure out how to do this. Can anyone please set me on the right track?

採用された回答

Chris
Chris 2021 年 11 月 6 日
編集済み: Chris 2021 年 11 月 6 日
% Find the index of the first minimum
TF=find(islocalmin(VarName2),1);
% Get the values for the lower and upper curves
lowerVal = VarName2(TF);
upperVal = VarName3(TF);
% Plot a value
plot(VarName1(TF),val1,'r*')
plot(VarName2(TF),val2,'r*')
% Display table. curveNum,lowerVal, and upperVal should be column vectors.
curveNum = ["VarName1";"VarName2"];
lowerVal = [1.4;1.5];
upperVal = [2;2.3];
T = table(curveNum,lowerVal,upperVal,'VariableNames',{'Curve','Lower','Upper'})
T = 2×3 table
Curve Lower Upper __________ _____ _____ "VarName1" 1.4 2 "VarName2" 1.5 2.3
If you want to add the table to the figure, it's a little more complicated. See the following link for a guide.
  3 件のコメント
Chris
Chris 2021 年 11 月 6 日
You're welcome. Tables are a little bit complicated. I edited my answer with a demo.
Srh Fwl
Srh Fwl 2021 年 11 月 6 日
Thanks for that. This is so helpful. Much less confusing to see what's happening in my plots now.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpecifying Target for Graphics Output についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by