finding maximum value of a plot

hi im need to know hoe to find the maximum value of a graph i have plptted in matlab.
the code is something like this:
a1=[1 2 3 4 5 6 7 8 9];
b1=[10 20 5 0 48 46 455 21 32];
plot(a1,b1);
not excatly as above but has many many values of x,y. Now i have got the plot and i need to find the maximum value of the plot i have got.
please help in finding it..maybe a matlab code for the same would be helpfull.

Antworten (2)

Eli Cuellar
Eli Cuellar am 7 Mär. 2019

7 Stimmen

I will assume you need to find both the maximum value in b1 as well as its corresponding a1 value. All you need to do is use the max() function. The max() function will return both the maximum value, and the index position of the value. You can use the index to extract the corresponding a1.
Example follows:
a1=[1 2 3 4 5 6 7 8 9];
b1=[10 20 5 0 48 46 455 21 32];
[b1_max, index] = max(b1);
a1_max = a1(index);
You can also plot the maximum value as so:
plot(a1, b1, a1_max, b1_max, 'ro')
The 'ro' option tells matlab to plot (a1_max, b1_max) in red, and using an 'o' as marker.
Hope it helps!

6 Kommentare

Danish Sarfaraz
Danish Sarfaraz am 7 Jun. 2020
very helpful thanks
Aero32
Aero32 am 2 Dez. 2020
is there a way to find a certain percentage of the max and the time that it occurs by using this?
William Eriksson Selin
William Eriksson Selin am 10 Mai 2021
Yes
Daniel Murphy
Daniel Murphy am 25 Feb. 2022
Thanks man
Michael Goshen
Michael Goshen am 11 Mär. 2022
What if you wanted a dotted line to go up to your 'o' marker?
Voss
Voss am 11 Mär. 2022
Bearbeitet: Voss am 11 Mär. 2022
a1=[1 2 3 4 5 6 7 8 9];
b1=[10 20 5 0 48 46 455 21 32];
[b1_max, index] = max(b1);
a1_max = a1(index);
plot(a1, b1, a1_max, b1_max, 'ro');
hold on
% plot([a1_max a1_max],[0 b1_max],'--m')
% plot([a1_max a1_max],[0 b1_max],'-.m')
plot([a1_max a1_max],[0 b1_max],':m')

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu MATLAB finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2018b

Gefragt:

am 7 Mär. 2019

Bearbeitet:

am 11 Mär. 2022

Community Treasure Hunt

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

Start Hunting!

Translated by