finding maximum value of a plot

278 次查看(过去 30 天)
Ajay Siddarth
Ajay Siddarth 2019-3-7
编辑: Voss 2022-3-11
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.

回答(2 个)

Eli Cuellar
Eli Cuellar 2019-3-7
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 个评论
Michael Goshen
Michael Goshen 2022-3-11
What if you wanted a dotted line to go up to your 'o' marker?
Voss
Voss 2022-3-11
编辑:Voss 2022-3-11
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')

请先登录,再进行评论。


madhan ravi
madhan ravi 2019-3-7
[max_value,index]=max(b1)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by