Find the max in a graph with multiple curves
16 ビュー (過去 30 日間)
古いコメントを表示
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
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
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 件)
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?
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Legend についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!