我的问题如下。 我正在编写一个Matlab脚本,我想在其中执行以下步骤:
我顺利完成了第1步和第2步,现在我正在进行第3步。让我们来看一个简单而虚构的例子:
contourline1 = [x1 y1 x2 y2 x3 y3 x1 y1];
contourline2 = [x4 y4 x5 y5 x6 y6 x4 y4];
以x1,... x6和y1,... y6作为实数(坐标)。因此,等高线1是轮廓,轮廓线2是“孔”(或者换句话说:等高线2是等高线1的真实子集)。现在我的目标是什么?
目标:我希望Matlab采用contourline1和contourline2并将其转换为SQL空间数据。 Matlab的输出应该是一个字符串,这样我就可以将其复制/粘贴到SQL中。输出字符串(SQL可读)应具有以下形式:
POLYGON((x1 y1, x2 y2, x3 y3, x1 y1),(x4 y4, x5 y5, x6 y6, x4 y4))
在我的剧本中,我已经将“outline”和“hole”结合起来:
outline_hole = [x1 y1 x2 y2 x3 y3 x1 y1 x4 y4 x5 y5 x6 y6 x4 y4];
这意味着Matlab必须用“(”,“)”和“,”来补充上面的矢量(outline_hole)。有人知道如何有效地做到这一点吗?
提前感谢您的帮助。
SpaceCowboy
答案 0 :(得分:0)
如果我理解你,你只想写一个字符串?
c1 = 1:8; % 1 2 3 4 5 6 7 8
c2 = 9:16; % 9 10 11 12 13 14 15 16
output = ['POLYGON((' num2str(c1(1:2)) ', ' num2str(c1(3:4)) ', ' ...
num2str(c1(5:6)) ', ' num2str(c1(7:8)) '),(' ...
num2str(c2(1:2)) ', ' num2str(c2(3:4)) ', ' ...
num2str(c2(5:6)) ', ' num2str(c2(7:8)) '))' ]
output =
'POLYGON((1 2, 3 4, 5 6, 7 8),(9 10, 11 12, 13 14, 15 16))'