Reshape a Matrix in a specific order
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Markus Kucera
el 3 de Mayo de 2018
Comentada: Ameer Hamza
el 4 de Mayo de 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 comentarios
Respuesta aceptada
Ameer Hamza
el 3 de Mayo de 2018
Editada: Ameer Hamza
el 3 de Mayo de 2018
"Since reshape dosent work"
reshape(matrix', 9, [])'
2 comentarios
Más respuestas (1)
Steven Lord
el 3 de Mayo de 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 comentarios
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!