Reshape a Matrix in a specific order
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Markus Kucera
am 3 Mai 2018
Kommentiert: Ameer Hamza
am 4 Mai 2018
Hello everyone, i have a 36x3 Matrix where every row represents the coordinates of a corner point of a triangle (x,y,z). So every three rows form a triangle. What i need is a 12x9 Matrix where every row represents a triangle (x1,y1,z1,x2,y2,z2,x3,y3,z3) Since reshape dosent work i tried using a for loop. This is how it would be if it was only one row
vert(1,1:3) = v(1,:)
vert(1,4:6) = v(2,:)
vert(1,7:9) = v(3,:)
And this is the for loop i have written:
for i = 1:nfaces
count = 3:nvert;
for j = count-2:nvert
for k = 1:3
for l = 1:9
vert(i,l) = v(j,k)
end
end
count+3;
end
end
nfaces is the total number of triangles i have and nvert is the number of corner points. In the end i get the 12x9 matrix but it seems that with every loop every element gets overwritten. e.g in the end all my elements are 50. i guess that i have to put a statement outside the loop but i havent figured out how to do it. I also tried other loops without the "count" but the result remains the same. I would appreciate it if someone could help me out and show me where i am wrong. Best regards, Markus
0 Kommentare
Akzeptierte Antwort
Ameer Hamza
am 3 Mai 2018
Bearbeitet: Ameer Hamza
am 3 Mai 2018
"Since reshape dosent work"
reshape(matrix', 9, [])'
2 Kommentare
Weitere Antworten (1)
Steven Lord
am 3 Mai 2018
Do you need the result to be a matrix of all the coordinates of the vertices of the triangles, or would you be able to work with the matrix of coordinates and a connectivity matrix? The triangulation object uses the latter approach, storing the coordinates in its Points property and the connectivity matrix in its ConnectivityList property. Based on your description, creating the connectivity matrix should be fairly straightforward.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!