Find the max in a graph with multiple curves
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Image Analyst
el 11 de Mzo. de 2019
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
el 11 de Mzo. de 2019
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.
Respuestas (2)
Adam
el 11 de Mzo. de 2019
Editada: Adam
el 11 de Mzo. de 2019
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 comentarios
Ver también
Categorías
Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!