2012-01-05 3 views
1

に私の機能をプロットします私は新しいMATLABのユーザーと私は機能をプロットしようとしています:どのように私はメッシュ

と呼ば
function [ uncertainty ] = uncertain(s1, s2, p) 
%UNCERTAIN calculates the measurement uncertainty of a triangulation 
% provide two coordinates of known stations and a target coordinate 
% of another point, then you get the uncertainty 
[theta1, dist1] = cart2pol(p(1)-s1(1), p(2)-s1(2)); 
[theta2, dist2] = cart2pol(p(1)-s1(1), p(2)-s2(2)); 
theta=abs(pi-theta2-theta1); 
uncertainty = dist1*dist2/abs(sin(theta)); 
end 

uncertain([0 0],[8 0],[4 4]) 

私は単一の結果を取得します。 しかし、私は全面をしたいと呼ばれる:

x=-2:.1:10; 
y=-2:.1:10; 
z = uncertain([0 0],[8 0],[x y]); 
mesh(x,y,z) 

私はエラーを取得する:「Zは行列ではなく、スカラーまたはベクトルでなければなりません。」

私の関数がサーフェスを描画するようにコードを変更するにはどうすればよいですか?

ありがとうございます。 Ralf。 。

答えて

1

まず、あなたの機能に間違いがあると思います。[theta2, dist2] = cart2pol(p(1)-s1(1), p(2)-s2(2));は、最初にs1s2である必要があります。

次に、ベクトルは、あなたのベクトル入力のために答える得るために、あなたは変更する必要があなたのp i番目の最初に選択されますp(i,:)に、(pのi番目の要素を選択)p(i)

その後、乗算(*)を要素ごとの乗算(.*)に変更します。要約する

function [ uncertainty ] = uncertain(s1, s2, p) 
%UNCERTAIN calculates the measurement uncertainty of a triangulation 
% provide two coordinates of known stations and a target coordinate 
% of another point, then you get the uncertainty 
% target coordinates p are 2xn 
% output uncertainty is 1xn 
[theta1, dist1] = cart2pol(p(1,:)-s1(1), p(2,:)-s1(2)); 
[theta2, dist2] = cart2pol(p(1,:)-s2(1), p(2,:)-s2(2)); 
theta=abs(pi-theta2-theta1); 
uncertainty = dist1.*dist2./abs(sin(theta)); 
end 

のみ変更がp(i)ある - >p(i,:)、及び* - >.*/ - >./

表面を得るために、あなたは、グリッド内の(x,y)座標のすべてのセットを取得uncertainため2xn行列にそれらを平らにして、プロットにグリッドにからそれらをバック展開するmeshgridを使用しています。例:

x=-2:.1:10; % 121 elements 
y=-2:.1:10; % 121 elements 
[xs,ys]=meshgrid(x,y); % xs and ys are each 121 x 121 
zs = uncertain([0 0],[8 0],[xs(:) ys(:)]'); %get zs, being 1x(121*121) ie 1x14641 
% Reshape zs to be 121x121 in order to plot with mesh 
mesh(xs,ys,reshape(zs,size(xs))) 

注:theta0またはpi(または非常に近い)であるときので、あなたが本当に大きな数字の多くを得るでしょう、あなたはあなたのために(ほぼ)0

+0

おかげで割っているので、回答。 あなたの変更内容を理解しようとしています。 しかし 角度が90°近くである必要があり、したがって、罪(角度)が、私はこのような画像を生成する醜いJavaコードを持っている1. の近くにする必要がありますので、その結果は、かなり予想外である: ます。http:// pastehtml .com/view/bjowk6rbg.html –

+0

しかし、私のmatlabコードはまだ100のような限界を逃しています:不確実性=最大(不確実、100)賢明な座標 そして、境界を絞り込む必要があります。 –

+0

私のコードには別のエラーがあります。3つの角度は三角形の3つの内側の角度(s1、s2、p)でなければならないため、180度でなければなりません。 –