How to mark the maximum of a surf plot
46 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Maria Anna
am 6 Jul. 2022
Kommentiert: Maria Anna
am 6 Jul. 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
0 Kommentare
Akzeptierte Antwort
Karim
am 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)
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)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Surface and Mesh Plots finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!