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 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Chris
Chris il 6 Nov 2021
Modificato: Chris il 6 Nov 2021
% 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 Commenti
Srh Fwl
Srh Fwl il 6 Nov 2021
Thanks for that. This is so helpful. Much less confusing to see what's happening in my plots now.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Specifying Target for Graphics Output in Help Center e File Exchange

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by