を使用しました様になる!
また、x
とy
座標のすべての組み合わせを取得するには、meshgrid
が必要です。
詳細については、コメントを参照してください。
% 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')
結果:
![plot](https://i.stack.imgur.com/1eu6J.png)
が
あなたの例をマッチングあなたはメープルコマンド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色を持つことによって発生するバンディングを滑らかにします。 g=3.5
(あなたが使用わからない)で
% 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)));
、我々はほとんど同じプロットを取得
![compare](https://i.stack.imgur.com/wZxn1.png)
私の編集を参照してください、私はカラーバンディングを滑らかにし、それを作る方法を示してきましたあなたのオリジナルのようにもっと見てください(興味があれば!) – Wolfie
これは元のような感じです。しかし、私はまだSの位置で明るい緑の色で白い点を逃しています。あなたは私がこれをどのように達成できるか知っていますか? 'scaletorange = -5..50、colorscheme = [black、" green "、" white "]'は、メイプルのトリックでした。 – smyslov
'g 'の価値は何ですか? 'g = 9.8'を使うと、私はより大きな白い斑点(密度> 50の大きなパッチ)を得る。あなたが答えるなら、正確なプロットを得るために修正を加えて私の質問を編集します:) – Wolfie