网格函数似乎交换x和y值 [英] Mesh function seems to swap x and y values

查看:106
本文介绍了网格函数似乎交换x和y值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在3d平面上绘制一个非常简单的函数.

I am trying to plot a very simple function in the 3d plane.

f=zeros(101,101);
xs=0:0.1:10;
ys=0:0.1:10;

for j=1:101
    f(1,j)=ys(j);
end

这是3个地块:

第一个是ymin时f vs x的图:

The first is a plot of f vs x at ymin:

figure; plot(xs,f(:,1),'*r')
xlabel('x')
ylabel('f')

第二个是xmin时f vs y的图:

The second is a plot of f vs y at xmin:

figure; plot(ys,f(1,:),'*r')
xlabel('y')
ylabel('f')

最后,第三个是3d网格:

And finally the third is a 3d mesh:

figure; mesh(xs,ys,f)
xlabel('x')
ylabel('y')

但是,网格图似乎与2 2d图相矛盾,如果让我知道,x和y似乎会切换.有人可以帮忙吗?出于某种原因,它应该是mesh(ys,xs,f)吗?谢谢!

However the mesh plot seems to contradict the 2 2d plots, it seems to have the x and y switched around if you get me. Can anyone help? Should it be mesh(ys,xs,f) for some reason? Thanks!

推荐答案

mesh并未切换您的xy,这只是定义问题.不要忘记矩阵没有x轴或y轴,而是具有行维和列维.行尺寸通常像x一样成对出现,但是如果也将其等同于图像,则通常会使x轴穿过,实际上是沿列轴!

mesh didn't switch your x and y, it's a matter of definition. Don't forget that a matrix doesn't have an x axis or a y axis but rather a row dimension and a column dimension. The row dimension is normally stated first in a pair just like the x dimension but if you are equating it too an image then you would normally have the x axis going across which is actually along the column axis!

宁愿这样尝试

for j=1:101
    f(j,1)=ys(j);
end

figure; plot(xs,f(1,:),'*r')
xlabel('x')
ylabel('f')

figure; plot(ys,f(:,1),'*r')
xlabel('y')
ylabel('f')

figure; mesh(xs,ys,f)
xlabel('x')
ylabel('y')

这篇关于网格函数似乎交换x和y值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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