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:
- Only show the first local minimum (right now I show all of them).
- Find the y value on the right-hand axis of the corresponding diagonal orange curve immediately above.
- 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?
0 个评论
采纳的回答
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'})
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
2021-11-6
You're welcome. Tables are a little bit complicated. I edited my answer with a demo.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!