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
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 CenterFile Exchange에서 Smoothing and Denoising에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by