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

7 次查看(过去 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 个评论

请先登录,再进行评论。

更多回答(0 个)

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by