Iは、次のベクターがきたと仮定すると:meshgridからノード数を正しく取得するにはどうすればよいですか?
x = [1 2 3 4];
y = [4 5 6];
z = [7 8 9];
私はグリッドにこれらをマージした後、X、Y、ZはnodeCountならびに座標を取得します。私はからコードしている:How do I obtain the count of corner points in a matrix as well as store their positions in an array?
次のように:
ny = length(y) - 1;
nx = length(x) - 1;
nz = length(z) - 1;
%# Obtain grid vectors
[ygv, xgv, zgv] = meshgrid(1:ny, 1:nx, 1:nz);
coords = [ygv(:), xgv(:), zgv(:)]
%# Obtain node counts
nodeCount = ny*nx*(coords(:,3) - 1) + nx*(coords(:,2) - 1) + coords(:,1)
%# Obtain coordinates
x_coord = mod(nodeCount - 1, nx) + 1;
y_coord = mod((nodeCount - x_coord)/nx, ny) + 1;
z_coord = (nodeCount - x_coord - nx*(y_coord - 1))/nx/ny + 1;
私の予想結果は次のようになります。ただし、コードはcords, ygv, xgv, and zgv
のためではなく、残りのための正しい結果を
coords = [1 1 1
1 2 1
1 3 1
2 1 1
2 2 1
2 3 1
1 1 2
1 2 2
1 3 2
2 1 2
2 2 2
2 3 2]
nodeCount = [1;2;3;4;5;6;7;8;9;10;11;12]
y_coord = [1;1;1;2;2;2;1;1;1;2;2;2]
x_coord = [1;2;3;1;2;3;1;2;3;1;2;3]
z_coord = [1;1;1;1;1;1;2;2;2;2;2;2]
を返します。 。私はnodeCount
がNOを数えていることを理解しています。行数はcoords
です。いずれにせよ、私はnodeCount
の式が間違っている可能性が高いと考えており、その後の計算に影響します。 nodeCount
を期待どおりに入手する方法はありますか?ありがとうございました!