How to rearrange the rows of a matrix so the column values loop

5 ビュー (過去 30 日間)
Joshua
Joshua 2013 年 6 月 19 日
I have a matrix
rec =
[ 0 0
0 0.4
0.2 0
1.0 0.4
1.0 0.9 ]
I want it rearranged so that it appears like so
rec_new =
[ 0.2 0
0 0
0 0.4
1.0 0.9
1.0 0.4 ]
If you take any one of these columns and concatenate it onto itself, the values loop from a minimum to a maximum. How can I get a program to automatically do this for a number of matrices? I'm not sure how to start this, so any help would be appreciated.
Ultimately, I need the pairs of points rearranged so that when they are graphed they form a polygon that does not intersect itself.
Thanks
  2 件のコメント
Angus
Angus 2013 年 6 月 19 日
編集済み: Angus 2013 年 6 月 19 日
It took me a bit but I understand what you wanted now, Ill think about it, it seems interesting. Best luck, Ill let you know if I come across something.
Joshua
Joshua 2013 年 6 月 20 日
Leah and Angus, I'd like to thank you both for your assistance. I appreciate it greatly.

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

採用された回答

Angus
Angus 2013 年 6 月 19 日
編集済み: Angus 2013 年 6 月 19 日
Hey that was interesting, I think this is what you want (not sure under what conditions it might fail):
rec = [0 0;0 0.4;0.2 0;1 0.4;1 0.9]
K = convhull(rec);
rec(K,:)
ans =
0 0
0.2000 0
1.0000 0.4000
1.0000 0.9000
0 0.4000
0 0
Came across this via Gift wrapping algorithm and then found convhull from there if you are interested.
It basically draws a line around the outside of the points ... kinda or something :D
Hope this does it for you,
Cheers, Angus.
  6 件のコメント
Angus
Angus 2013 年 6 月 21 日
hey again, so convhulln seems to be the same as convhull in the 3d case for practical purposes. Using convhull and trisurf as in my previous comment produced a nice 3d plot of a filled polygon, is that what you are aiming for in this case?
In reviewing your original question it seems you might want to actually rearrange the structure of the matrix, is this still necessary since it can be plotted successfully without manipulation?
Joshua
Joshua 2013 年 6 月 24 日
I do want to rearrange the structure of the matrix. I need to be able to do some calculations with them for the area and perimeter of the polygon the points create

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

その他の回答 (1 件)

Leah
Leah 2013 年 6 月 19 日
"If you only want them to be counter-clock wise, why not convert the [x,y] point to polar coordinate and sort them by angle?"
  2 件のコメント
Joshua
Joshua 2013 年 6 月 20 日
would this work in 3d?
Leah
Leah 2013 年 6 月 20 日
I don't really know that this makes sense in 3D. If you had a mesh making up a sphere what order would you want them to go in? Clockwise direction doesn't mean anything in 3D space. I think you need to rethink your desired outcome in 3D space.

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

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by