所以我有一个非常长的函数,它绘制了一个更高级的函数的高度,有很多峰和谷。
我应该画出这个约束在x和y轴上的曲面,这里x的跨度是从0到10,1000个等间距的点,y也是如此。
然而,我并不真正理解网格和网格的复杂之处。
如前所述,这里是我应该绘制的复杂函数。
function z = topography(x,y)
z= 0.001*(x-3).^2 +0.001*(y-4).^2 ...
+0.5*exp(-0.25.*(x-11).^2-0.01*y.^2)...
+0.5*exp(-0.01.*x.^2-0.25*(y-11).^2)...
+0.5*exp(-0.1.*(x+1).^2-0.01*(y-5).^2)...
+0.3*exp(-0.1.*(x-3.5).^2-0.5*(y+1).^2)...
+0.5*exp(-0.1.*(x-8).^2-0.1*(y-0).^2)...
+1.*exp(-0.1.*(x-9).^2-0.1*(y-8.5).^2)...
+0.5*exp(-0.5.*(x-6).^2-0.1*(y-6).^2)...
+0.25*exp(-0.5.*(x-3).^2-0.5*(y-8).^2)...
+0.5*exp(-(x-5).^2-0.5*(y-5).^2)...
+0.25*exp(-0.75.*(x-2).^2-(y-8).^2)...
+0.5*exp(-(x-6).^2-0.5*(y-3).^2)...
+0.5*exp(-(x-5).^2-0.5*(y-9).^2)...
+0.5*exp(-(x-9).^2-0.5*(y-5).^2);
end下面是不使用meshgrid的方法:
xx=linspace(0,10,1000); % A vector with x-values from 0 to 10
yy=linspace(0,10,1000); % A vector with y-values from 0 to 10
zz=zeros(length(xx)); % A matrix of z-values
for i = 1 : length(xx)
for j = 1 : length(yy)
zz(i,j)= topography(xx(j),yy(i));
end
end
figure(1);
mesh(xx, yy, zz) % The graph z=f(x,y) for topography这是我使用meshgrid将其转换为脚本的尝试
xx = linspace(0,10,1000);
yy=linspace(0,10,1000);
zz=topography(x,y);
[x,y,z]=meshgrid(xx,yy,zz);
mesh(z);我希望有一个很好的3D图形来描述冗长的函数"topograph“。相反,我得到了错误消息:
Requested 1000x1000x10201 (76.0GB) array exceeds maximum array size
preference. Creation of
arrays greater than this limit may take a long time and cause MATLAB to become
unresponsive.
See array size limit or preference panel for more information.
Error in meshgrid (line 77)
xx = repmat(xx, ny, 1, nz);
Error in figure11 (line 6)
[x,y,z]=meshgrid(xx,yy,zz);它说数组超过了数组限制。但是,为什么工作脚本不是使用循环来完成这一点呢?
发布于 2019-04-13 12:18:12
meshgrid通常仅用于生成自变量。一旦创建了自变量网格,就可以使用它们来计算因变量。
因此,在您的脚本中,x-y平面是使用meshgrid创建的,而地形(即高度)是通过使用这些栅格计算函数来创建的:
x = linspace(0,10,1000);
y = linspace(0,10,1000);
[xx, yy] = meshgrid(x,y);
zz = topography(xx, yy);
mesh(xx, yy, zz);这假设函数是完全向量化的,因此它可以接收到矩阵并产生大小相等的矩阵。而发布的地形函数似乎就是这样。
https://stackoverflow.com/questions/55660249
复制相似问题