Reshape a Matrix in a specific order

10 ビュー (過去 30 日間)
Markus Kucera
Markus Kucera 2018 年 5 月 3 日
コメント済み: Ameer Hamza 2018 年 5 月 4 日
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

採用された回答

Ameer Hamza
Ameer Hamza 2018 年 5 月 3 日
編集済み: Ameer Hamza 2018 年 5 月 3 日
"Since reshape dosent work"
reshape(matrix', 9, [])'
  2 件のコメント
Markus Kucera
Markus Kucera 2018 年 5 月 4 日
編集済み: Markus Kucera 2018 年 5 月 4 日
OKay now i feel a little bit stupid, it seems like i didnt quite understand how reshape works... But thanks for your help, i really appreciate it.
Ameer Hamza
Ameer Hamza 2018 年 5 月 4 日
You are welcome.

サインインしてコメントする。

その他の回答 (1 件)

Steven Lord
Steven Lord 2018 年 5 月 3 日
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.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by