MatLab - Euclidean Distance Plot 3D

99封情书 提交于 2019-12-23 05:12:30

问题


Im new in matlab programming and I have small issue.

I want to draw a plot 3d of Euclidean distance function for 2 coordinates, like in this picture below:

Could you help me with the source code? How I can draw this plot? My first thoughts was wrong:

[A] = meshgrid(-100:.5:100, -100:.5:100);   
D1 = bwdist(A);
figure
surf(double(A), double(D1)) 

回答1:


It is done like this...

[x, y] = meshgrid(-100:.5:100, -100:.5:100);   

The you have to calculated the euclidean distances. I assume you want them with the origin.

z = (x.^2 + y.^2).^0.5;   % square root of sum of squares (euclidean distance with origin)
surf(x, y, z);

NOTE: meshgrid(-100:.5:100, -100:.5:100) might make the resolution of the plot too high. If you have trouble viewing the plot, reduce the resolution.

Use [x, y] = meshgrid(-100:5:100, -100:5:100);



来源:https://stackoverflow.com/questions/20839329/matlab-euclidean-distance-plot-3d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!