问题
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:
![](https://www.eimg.top/images/2020/03/24/cba778d71eee2362e32c43c54cc79d7c.png)
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