【问题标题】:Changing look of meshc plot in matlab在matlab中改变meshc图的外观
【发布时间】:2016-05-25 10:19:09
【问题描述】:

我有一些代码可以创建随机景观和轮廓,但我无法控制颜色、阴影、轮廓线颜色、轮廓线数量等。我发现谷歌搜索没有任何帮助。代码如下:

function create_landscape()

Lx=1;
dx=0.01;
x=0:dx:Lx;
nx=length(x);
Ly=5;
dy=0.01;
y=0:dy:Ly;
ny=length(y);

[mgx,mgy]=meshgrid(x,y);
landscape=zeros(ny ,nx);
nhills=100;
maxh=1;
maxw=0.03;
maxl=maxw*Ly/Lx;
xbuf=0.1;
ybuf=0.1;
pd=makedist('Normal','mu',0,'sigma',1e-5*exp(-1));

for i=1:nhills
    center=[xbuf+(Lx-2*xbuf)*rand,ybuf+(Ly-2*ybuf)*rand];
    w=rand*maxw;
    l=rand*maxl;
    sign=(-1)^(ceil(2*rand));
    h=random(pd)*maxh/1e-5;
    landscape=landscape+hill(mgx,mgy,sign*h,center,w,l);
end

m=meshc(mgx,mgy,landscape);
axis([-0.2 Lx+0.2 -0.2 Ly+0.2 -maxh*1.5 maxh*3])
grid off
xlabel('x')
ylabel('y')
hold off;

end

function fx=hill(x,y,h,center,w,l)
fx=h*exp(-(x-center(1)).*(x-center(1))/w^2).*exp(-(y-center(2)).*(y-center(2))/l^2);
end

知道如何改变它的外观吗?

【问题讨论】:

    标签: matlab colors mesh contour


    【解决方案1】:

    您可以使用colormap函数更改颜色

    如果你想要一个平面,你可以使用surfc(...,...,...,'EdgeColor','none')函数来代替网格函数。

    如果要创建具有更多线条的景观,则必须更改参数 dxdy

    colormap('pink') 将为您提供以下结果(您也可以定义自己的颜色图),左侧是函数 surfc,右侧是函数 meshc。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-04
      • 2012-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多