![1How can I show (x,y) of a point in fsurf function - 2019 12 01.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/251800/1How%20can%20I%20show%20(x,y)%20of%20a%20point%20in%20fsurf%20function%20-%202019%2012%2001.png)
How can I show (x,y) of a point in fsurf function?
3 次查看(过去 30 天)
显示 更早的评论
I have the following script:
Rx = eye(2);
Rdx = [2; 4.5];
wo = inv(Rx)*Rdx;
var_d = 24.4;
syms w1 w2
vec_w = [w1 ; w2];
J(w1,w2) = var_d - 2*vec_w'*Rdx + vec_w'*Rx*vec_w
fsurf(J)
hold on
fsurf(wo(1),wo(2),J(wo(1),wo(2)),'Marker','diamond','MarkerFaceColor','r', 'MarkerSize',16)
xlim([-4.25 5.75])
ylim([-1.61 8.39])
zlim([-36 104])
view([99 20])
I get this Figure:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/251789/image.png)
It's pretty good, actually. But I would like to show the (x, y) coordinates of my red point. In my mind, I imagine achieve something like that (I do that in a imagem editor):
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/251790/image.png)
How can I do that in Matlab? Thanks :)
0 个评论
采纳的回答
Star Strider
2019-12-2
Try this:
Rx = eye(2);
Rdx = [2; 4.5];
wo = Rx\Rdx;
var_d = 24.4;
syms w1 w2
vec_w = [w1 ; w2];
J(w1,w2) = var_d - 2*vec_w'*Rdx + vec_w'*Rx*vec_w;
Jfcn = matlabFunction(J);
xv = linspace(-4.25, 5.75, 25);
yv = linspace(-1.61, 8.39, 25);
[X,Y] = ndgrid(xv,yv);
Z = Jfcn(X,Y);
figure
surf(X, Y, Z)
xlim([-4.25 5.75])
ylim([-1.61 8.39])
zlim([-36 104])
hold on
plot3(2, 4.3, Jfcn(2,4.3),'Marker','diamond','MarkerFaceColor','r', 'MarkerSize',16);
plot3([min(xlim) 2], [0 0]+4.3, [0 0]+min(zlim), '--k')
plot3([0 0]+2, [min(ylim) 4.3], [0 0]+min(zlim), '--k')
plot3([0 0]+2, [0 0]+4.3, [min(zlim) Jfcn(2,4.3)], '--k')
hold off
view([99 20])
I got tired of waiting fot the fsurf plots to calculate and plot (even on my Ryzen 7 1800X it takes forever), so I did a numieric shortcut. This gives the basic idea for you to experiment with, produicng:
![1How can I show (x,y) of a point in fsurf function - 2019 12 01.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/251800/1How%20can%20I%20show%20(x,y)%20of%20a%20point%20in%20fsurf%20function%20-%202019%2012%2001.png)
更多回答(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!