如何在MATLAB中绘制矩形 [英] How to plot a rectangular in MATLAB

查看:203
本文介绍了如何在MATLAB中绘制矩形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对我来说,有必要在MATLAB中按轮廓绘制矩形.但是当我绘制此图时,该图就像正方形,而不是矩形.

实际上X轴和Y轴的长度是正确的,但图形不是矩形的.

如何找到一个矩形图形?

在我需要通过countour绘制一个椭圆像圆之前,通过设置 axes([xmin xmax ymin ymax]),此问题已解决,但知道此命令无效./p>

这是我的代码 u0 x y 是3个长度为 nx * ny 的向量.和 nx ny 是x轴和y轴上的点数.

 图对于i = 1:nyz(i,:)= u0((i-1)* nx + 1:i * nx);x1(i,:)= x((i-1)* nx + 1:i * nx);y1(i,:)=y((i-1)*nx+1:i*nx);结尾;cMap = [0.45 0.6 0.65; 1 1 1];%[绿色;黄色]在RGB颜色上colormap(cMap);轴相等Silhouettef(x1,y1,z,'LineColor','none')彩条 

让's = 0:0.1:0.2'和'x = repmat(s,1,ny)'和'd = 0:0.1:1','y = repmat(d,1,nx)''u0 = x + y'

解决方案

我认为问题在于您正在使用的向量的大小.看看这个例子:

  x = linspace(0,2,20);y = linspace(0,1,10);z = meshgrid(x,y);等高线f(x,y,z,20);轴相等 

它给出以下结果:

现在,如果我们检查尺寸:

 >>尺寸(x)回答=1 20>>尺寸(y)回答=1 10>>尺寸(z)回答=10 20 

如果x向量的大小等于y向量的大小,则显然可以得到一个平方!就您而言,在使用 contourf 之前,请先检查x1,y1,z的大小,并确保之后使用的轴相等.

It is necessary for me that plot a rectangular in MATLAB by contour. But when I plot this, the figure is like square and no rectangular.

In fact the length of X axis and Y axis are true, but figure is not rectangular.

How could I find a rectangular figure?

Once before I needed to plot a n eliptical by countour and it was like circle, by setting axes([xmin xmax ymin ymax]) this problem was solved but know this command do not work.

Here is my code u0,x,y are 3 vectors of length nx*ny. and nx and ny are the number of points in x axis and y axis.

figure 
for i=1:ny
    z(i,:)=u0((i-1)*nx+1:i*nx);
    x1(i,:)=x((i-1)*nx+1:i*nx);
    y1(i,:)=y((i-1)*nx+1:i*nx);
end;

cMap = [0.45 0.6 0.65;1 1 1]; % [green;yellow] on rgb-color
colormap(cMap);
axis equal
contourf(x1,y1,z,'LineColor','none')
colorbar

Let 's=0:0.1:0.2' and 'x=repmat(s,1,ny)' and 'd=0:0.1:1', 'y=repmat(d,1,nx)' 'u0=x+y'

解决方案

I think the problem is the size of the vector you are using. Check out this example:

x = linspace(0,2,20);
y = linspace(0,1,10);
z = meshgrid(x,y);
contourf(x,y,z,20);
axis equal

it gives the following result:

Now if we check the sizes:

>> size(x)

ans =

     1    20

>> size(y)

ans =

     1    10

>> size(z)

ans =

    10    20

if the size of x vector is equal to the size of the y vector it gives you a square obviously! in your case first check the size of x1, y1, z just before using the contourf an make sure that you are using axis equal after that.

这篇关于如何在MATLAB中绘制矩形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆