Angenommen I haben die folgenden Vektoren:Wie erhalte ich Knotenanzahl korrekt von Meshgrid?
x = [1 2 3 4];
y = [4 5 6];
z = [7 8 9];
I diese in Rastern zusammenführen möchten und dann erhalten die x, y, z sowie nodeCount Koordinaten. Ich habe den Code aus: How do I obtain the count of corner points in a matrix as well as store their positions in an array?
Wie folgt:
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;
Mein erwartetes Ergebnis wäre:
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]
jedoch der Code nur korrekte Ergebnisse für cords, ygv, xgv, and zgv
zurückgibt, aber nicht für den Rest . Ich verstehe die nodeCount
zählt die Nr. von Reihen in coords
. In jedem Fall vermute ich, dass die nodeCount
Formel wahrscheinlich falsch ist, was sich dann auf die nachfolgenden Berechnungen auswirkt. Bitte gibt es eine Möglichkeit, die nodeCount
wie erwartet zu bekommen? Vielen Dank!