MATLAB绘制表面的一部分 [英] MATLAB plot part of surface
问题描述
说我有以下脚本:
u = -5:.2:5;
[X,Y] = meshgrid(u, u);
Z = cos(X).*cos(Y).*exp(-sqrt(X.^2 + Y.^2)/4);
surf(X,Y,Z);
无论如何,我是否可以使MatLab仅绘制表面的一部分?举例来说,我只想绘制一个点或单个网格,该怎么办?我想也许要画一个我可以使用的点:
Is there anyway that I can make MatLab plot only parts of the surface? Say, for instance, I just want to plot a single point, or a single grid, what can I do? I thought perhaps to plot a single point I could use:
surf(X(1,1), Y(1,1), Z(1,1))
但是随后我收到错误消息:
But then I get the error message:
??? Error using ==> surf at 78
Data dimensions must agree.
我非常感谢您在此提供的一些帮助/帮助.在此先感谢:)
I would really appreciate some input/help here. Thanks in advance :)
推荐答案
当我尝试尝试时,会得到以下信息:
When I try what you tried, I get the following:
surf(X(1,1),Y(1,1),Z(1,1))
使用Surf(第75行)Z时出错,它必须是矩阵,而不是标量或向量.
surf(X(1,1),Y(1,1),Z(1,1))
Error using surf (line 75) Z must be a matrix, not a scalar or vector.
因此,问题在于您不能仅使用surf
进行点或线的操作,而必须使用其他函数.但是您可以选择子区域
So the problem is that you can't do just a point or line using surf
, you'd have to use a different function. But you can select subregions
>> ii=1:5;
>> jj=1:20;
>> surf(X(ii,jj),Y(ii,jj),Z(ii,jj))
另一种方法是使用NaNs作为掩膜.
Another way to do it is to use NaNs as a mask.
>> mask = ones(size(X));
>> mask(1:20, 20:end) = nan;
>> surf(X.*mask, Y.*mask, Z.*mask)
这将使显示NAN的部分不显示.
This will make the parts where NANs are present not be displayed.
这篇关于MATLAB绘制表面的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!