Find the max in a graph with multiple curves

6 ビュー (過去 30 日間)
amsel
amsel 2019 年 3 月 11 日
編集済み: Adam 2019 年 3 月 11 日
Hi,
I have a lot of graphs in a figure and i need to know for every abciss the curve that matches the max.
I already know how to do it with only 1 curve.
Here is my graph :
For example while x is between 6 and 11 the program needs to return the value of beta=0° (the blue curve) .
My code :
for b=0:5:30
li=(((b.^3)+1).*(l+0.08*b))./(((b^3)+1)-(0.035.*(l+0.08*b)));
cp=c1.*((c2./li)-c3*b-c4).*exp(-c5./li)+c6.*l;
txt=['Bêta=',num2str(b)];
plot(l,cp,'DisplayName',txt)
xlim([2 25])
ylim([0 0.5])
hold on;
%Z=[Z max(cp)];
[Z,I]=max(cp);
X=[X Z];
W=[W I];
A=[l(W)];
end
X; % y max of the cp for every beta
A' % x of the max point for every beta
W; %order of the max of cp for every beta
hold off;
legend show
  2 件のコメント
Image Analyst
Image Analyst 2019 年 3 月 11 日
Your code doesn't run
Undefined function or variable 'l'.
Error in test2 (line 2)
li=(((b.^3)+1).*(l+0.08*b))./(((b^3)+1)-(0.035.*(l+0.08*b)));
Please tell us what l (lower case L) is. Also, l is a very very bad variable to use since it looks so much like 1 (one) and I (upper case i).
Adam
Adam 2019 年 3 月 11 日
You didn't say what the problem is with your current code. What result do you get? what is wrong with it?
Creating a pre-sized array and indexing into it to store results in a loop is better than concatenating in a loop, but that is just semantics and better coding style, the end result will still be the same as concatenating.

サインインしてコメントする。

回答 (2 件)

amsel
amsel 2019 年 3 月 11 日
The context is that I'm doing mechanical optimization for wind turbine, in x I have wind speed and in y I have the efficiency of the wind turbine. For every speed, I need to choose the right angle in order to have the maximum efficiency .
That's why I'm asking about how can the code return the beta .
Maybe if you have another idea it will be very helpful
Thank you ;)
Here is the entire code :
clear all;
close all;
clc;
A=[];
X=[];
W=[];
Z=[];
v=[3:0.2:28];
l=14*4.5./v;
c1=0.5109;
c2=116;
c3=0.4;
c4=5;
c5=21;
c6=0.0068;
for b=0:5:30
li=(((b.^3)+1).*(l+0.08*b))./(((b^3)+1)-(0.035.*(l+0.08*b)));
cp=c1.*((c2./li)-c3*b-c4).*exp(-c5./li)+c6.*l;
txt=['Bêta=',num2str(b)];
plot(l,cp,'DisplayName',txt)
xlim([2 25])
ylim([0 0.5])
hold on;
%Z=[Z max(cp)];
[Z,I]=max(cp);
X=[X Z];
W=[W I];
A=[l(W)];
end
X; % y max of the cp for every beta
A' % x of the max point for every beta
W; %order of the max of cp for every beta
hold off;
legend show

Adam
Adam 2019 年 3 月 11 日
編集済み: Adam 2019 年 3 月 11 日
b=0:5:30;
li=(((b'.^3)+1).*(l+0.08*b'))./(((b'.^3)+1)-(0.035.*(l+0.08*b')));
cp=c1.*((c2./li)-c3.*b'-c4).*exp(-c5./li)+c6.*l;
will give you all curves in a single matrix. If what you are saying you want is to knnow which curve has the highest y-value for each x-value then you can just use:
[m, idx] = max( cp );
where m will be the amplitude of the max curve and idx will be its index, from 1 to 7.
Is this the code that produces your attached plot in the original question though as the plots I get look nothing like that?

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by