How to mark the maximum of a surf plot

8 vues (au cours des 30 derniers jours)
Maria Anna
Maria Anna le 6 Juil 2022
Commenté : Maria Anna le 6 Juil 2022
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

Réponse acceptée

Karim
Karim le 6 Juil 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)
  1 commentaire
Maria Anna
Maria Anna le 6 Juil 2022
Ohhh yes of course, thank you

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by