本文介绍了MatLab-欧氏距离图3D的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Matlab编程的新手,我有个小问题.

Im new in matlab programming and I have small issue.

我想绘制2个坐标的欧几里得距离函数的图3d,如下图所示:

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))

推荐答案

它是这样完成的...

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);

注意:meshgrid(-100:.5:100,-100:.5:100)可能会使绘图的分辨率过高.如果您在查看绘图时遇到问题,请降低分辨率.

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.

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

这篇关于MatLab-欧氏距离图3D的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 23:21