How to mark the maximum of a surf plot
37 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Karim
2022-7-6
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)
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)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!