How to mark the maximum of a surf plot

30 visualizzazioni (ultimi 30 giorni)
Hello,
I want to mark the maximum of a surf plot, thats my code, but it isn't working and always puts out a false maximum:
alpha=50;
beta=20;
t=trnd(1,1,20);
x=alpha+beta*t;
a = linspace(35,65,1000);
b = linspace(-50,50,1000);
[a2,b2,x2] = meshgrid(a,b,x);
likeli=prod(b2./(pi*((x2-a2).^2+b2.^2)),3);
[maxV, maxL] = max(likeli(:));
[maxa, maxb] = ind2sub(size(likeli),maxL)
figure
contour(likeli,50)
hold on
axis auto
xline(maxa,'r')
yline(maxb,'r')
hold off

Risposta accettata

Karim
Karim il 6 Lug 2022
I'm guessing you switched maxa and maxb. Note that the columns are plotted on the x axis and the rows on the y axis.
alpha=50;
beta=20;
t=trnd(1,1,20);
x=alpha+beta*t;
a = linspace(35,65,1000);
b = linspace(-50,50,1000);
[a2,b2,x2] = meshgrid(a,b,x);
likeli=prod(b2./(pi*((x2-a2).^2+b2.^2)),3);
[maxV, maxL] = max(likeli(:));
[maxa, maxb] = ind2sub(size(likeli),maxL)
maxa = 371
maxb = 359
figure
contour(likeli,50)
hold on
axis auto
xline(maxb,'r')
yline(maxa,'r')
hold off
% have a look in 3D
figure
surf(likeli,'EdgeColor','none')
hold on
axis auto
scatter3(maxb,maxa,maxV,50,'r','filled')
hold off
view(3)

Più risposte (0)

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by