regroup identical coordinate pair

3 次查看(过去 30 天)
Hi everyone,
I've got vectors like this corresponding to the coordinates of a point:
X = [1;1;8;5;5;6]
Y = [2;2;5;6;6;7]
and would like to regroup points that have the same coordinates and have the following results :
R_X = [1;8;5;6];
R_Y = [2;5;6;7];
Are there any functions or way to concatenate that would help me to do that ?
Thanks

采纳的回答

Star Strider
Star Strider 2020-6-4
I have no idea what your objective is, however the unique function will produce the result you posted:
RX = unique(X,'stable')
RY = unique(Y,'stable')
producing:
RX =
1
8
5
6
RY =
2
5
6
7
  6 个评论

请先登录,再进行评论。

更多回答(1 个)

Adam Danz
Adam Danz 2020-6-4
[~, unqIdx] = unique([X(:), Y(:)], 'rows','stable');
R_X = X(unqIdx);
R_Y = Y(unqIdx);

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by