How to mark the maximum of a surf plot

8 views (last 30 days)
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

Accepted Answer

Karim
Karim on 6 Jul 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)

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!