Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

reorder the data array for the least distance

조회 수: 1 (최근 30일)
Feng
Feng 2018년 8월 29일
마감: MATLAB Answer Bot 2021년 8월 20일
I have a data array
a =
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 0 0 0 0 0 1 1 0 0 0 0 0 1 1
1 1 0 0 0 0 0 1 1 0 0 0 0 0 1 1
1 1 0 0 0 0 0 1 1 0 0 0 0 0 1 1
1 1 0 0 0 0 0 1 1 0 0 0 0 0 1 1
1 1 0 0 0 0 0 1 1 0 0 0 0 0 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Which I converted into a two column data array by picking up all the ones using
CC = bwconncomp(a)
data = regionprops(CC, 'PixelList')
The new data is organized by rows, e.g.,
3 1
3 2
3 8
3 9
4 1
4 2
4 8
4 9
.....
I would like to reorganize it like
3 1
3 2
4 1
4 2
.....
3 8
3 9
4 8
4 9
.....
so the connected points are next to each other. Any idea on how to achieve this?
Thanks!

답변 (2개)

Stephen23
Stephen23 2018년 8월 29일
편집: Stephen23 2018년 8월 29일
You can easily use sortrows to get a very similar sequence, which keeps the connected points together, as you requested:
sortrows(data,[2,1])

Feng
Feng 2018년 8월 29일
Thanks, Stephen, for your help. I tried and instead of going going vertically, it is now going horizontally. The order is from RED to YELLOW as before (picture1) and after (picture2). But what I would like is from RED to GREEN as in picture1

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by