スタックオーバーフローのユーザーの皆様、
数年前、私は数ヶ月間数学を使いました。数年間プログラミングをしなかった後、私は学生として、Matlabを使用する研究プロジェクトを行っています。私はここでstackoverflowに関して多くの良い助けを見つけました、しかし今私は次の問題で立ち往生しています:
長方形グリッド上のノード間の接続のデータセットがあります。各ノードには、8つの隣接ノードへの接続があります。私の測定値は3行n列の行列の形式で、最初の2つの値はノードを示し、3番目の値はそれらが接続されているかどうかを示します。グリッドのサイズは事前に決定されています。通常、互いに少なくとも1つ隣接している2つまたは3つのノードからの約10本の線があります。私の研究プロジェクトの目標は、この線の集まりの周りの距離rの面積を計算することです。
これまでのところ、以下のコードで行をプロットすることができました。ここからスタックオーバーフローでコードのビットを使用しました。これは非常に便利でした。ただし、特定の距離でその周りの等高線を取得できません(この等高線の内側の面積を計算したいと思います)。gplot関数は、1行に2つの座標を持つ2つのベクトルを返しますが、これをより使いやすいものに変換するのは難しいと思います。線からの距離とともに値Zを定義して、線からの距離とともに減少するようにしたので、これらの線から傾斜が得られます。この勾配から等高線を計算できます。ただし、線は単なる座標であるため、関数である場合とは対照的に、その線までの距離を計算する方法がわかりません。
私は本当に途方に暮れています。私はここに私の問題をいくらか明確に投稿したことを望みます。この問題を投稿するのはこれが2回目ですが、コードと写真にコメントを追加して、自分自身をよりよく説明できるようにしました。アドバイスをありがとう!
これまでのところ、xlsファイルは上記の3行n列の行列です。また、以下のコードでその内容を行列形式で記述しているため、問題を理解しやすくなっています。
%# here i set my data/constants
filename='random.xls'; file=xlsread(filename); y=width; x=length;
%# random.xls looks approximately like this, after xlsread(filename) you get
file=[21 22 1;
21 20 1;
15 16 1;
15 14 1;
15 23 1;
14 22 1;
14 21 1;
22 15 1;
23 14 1;
24 15 1;
6 15 1;
5 14 1;
7 14 1;
8 15 1];
%# predefined width and length, i usually get this from the file
width=8; length=4;
%# here i create my adjaceny matrix in a elegant way user amro posted on stackoverflow
%# however i immediately multiply it by 0, creating a y*x by y*x matrix with all zeroes
[X Y] = meshgrid(1:x,1:y); X = X(:); Y = Y(:);
adjacency = squareform( pdist([X Y], 'chebychev') == 1 ); adjacency=adjacency*0;
%# here i take the matrix "file" for which the first two values are node numbers and
%# the third value designates whether there is a connection between the two nodes to
%# fill in the connections in the adjacencymatrix
[nrows,ncols]=size(file);
for r = 1:nrows
if file(r,3)==1
adjacency(file(r,1),file(r,2))=1;
end
end
adjacency=(adjacency+adjacency.');
%# plots the adjacencymatrix
subplot(121), spy(adjacency)
%# plots the connections and designates the nodes, note that the numbers designating
%# the nodes do not match original data, this is a separate problem i have not solved
[xx yy] = gplot(adjacency, [X Y]);
subplot(122), plot(xx, yy, 'ks-', 'MarkerFaceColor','b')
%# these last lines of code for plotting the numbers of the grid i do not fully
%# understand, in here is the cause for the numbers not matching the original data
axis([0 x+1 0 y+1])
[X Y] = meshgrid(1:x,1:y);
X = reshape(X',[],1) + 0.1; Y = reshape(Y',[],1) + 0.1;
text(X, Y(end:-1:1), cellstr(num2str((1:x*y)')) )
xlabel('length')
ylabel('width')
title(filename)
私の問題を明確にするために、私はこれらの2つの写真を追加しました:現在のプロットhttp://imgur.com/5uPd4 私が知りたいエリアhttp://imgur.com/WsIbg