可以使用surf
(三维曲面图)来实现这一点,但你需要一个更精细的网格比它的10个步骤为了看上去好点!
您还需要meshgrid
才能获得所有组合的x
和y
坐标。
请参阅有关进一步的细节的意见。
% Set up grid points
x = 0:0.1:100;
y = -50:0.1:50;
[x,y] = meshgrid(x,y);
% Set up parameters i, s and g
i = [50 25]; s = [10 0]; g = 9.8;
% Work out density
% - no need for loop if we use element-wise operations ./ and .^
% - power(z,2) replaced by z.^2 (same function, more concise)
% - You forgot the sqare roots in your question's code, included using .^(1/2)
% - line continuation with "...", could remove and have on one line
sir = -10*g*log10(((x-s(1)).^2 + (y-s(2)).^2).^(1/2) ./ ...
((x-i(1)).^2 + (y-i(2)).^2).^(1/2) );
% Plot, and set to a view from above
surf(x,y,sir,'edgecolor','none','facecolor','interp');
view(2);
% Change the colour scheme
colormap('bone')
结果:
匹配您的例子
您使用的枫叶命令scaletorange=-5..50
。这限制-5
和50
(docs)之间的规模,这样以来sir
是我们的规模可变的,我们应该限制它一样。在MATLAB:
% Restrict sir to the range [-5,50]
sir = min(max(sir,-5),50);
% Of course we now have to replot
surf(x,y,sir,'edgecolor','none','facecolor','interp');
view(2);
现在,如果你想黑/绿颜色,你可以使用自定义colormap
,这也将理顺造成'bone'
colormap
唯一有64种颜色的条纹。
% Define the three colours to interpolate between, and n interpolation points
black = [0 0 0]; green = [0 1 0]; white = [1 1 1];
n = 1000;
% Do colour interpolation, equivalent to Maple's 'colorscheme = [black, "green", "white"]'
% We need an nx3 matrix of colours (columns R,G,B), which we get using interp1
colormap(interp1(1:3, [black; green; white], linspace(1,3,n)));
随着g=3.5
(不知道你用什么),我们得到几乎相同的情节
请看看我的编辑,我展示了如何顺利进行,色带,并使其看起来更像原来的(如果你有兴趣!) – Wolfie
这似乎更像原来的。不过,我仍然在S的位置丢失了浅绿色的白色斑点。你碰巧知道我怎么能做到这一点? 'scaletorange = -5..50,色彩方案= [黑, “绿色”, “白”]'的确在枫的伎俩。 – smyslov
你使用了什么'g'的值?如果我使用'g = 9.8',我会得到一个更大的白点(更大的贴片,其密度> 50)。如果你回答,我会编辑我的问题与修复得到确切的情节:) – Wolfie