필터 지우기
필터 지우기

Reading image in zig zag, and arrange the output matrix in ascending and descending issue

조회 수: 2 (최근 30일)
I am trying to image a figure and create G-code by reading the figure in zig-zag way. Thus, first I red the figure and dedect the edges and generate matrix for the edges.
The generated matrix like this:
AA =
[ 21 13
22 13
23 13
24 13
41 13
42 13
43 13
44 13
45 13
46 13
18 14
19 14
20 14
25 14
26 14
27 14
28 14
47 14
48 14
17 15
29 15
41 15
48 15
. . ], so on.
What I need to do to, arrange the first colume at coloume two value 13 by ascending way, and at second column value 14 by decending way and so on.
after that, I want to format these coordiantions in G-code format
How can I do this?
attached is an example for my code until and a figure sample
  댓글 수: 2
Image Analyst
Image Analyst 2020년 7월 9일
Not sure I understand but perhaps you want sort() or sortrows().
Islam Hassan
Islam Hassan 2020년 7월 9일
Yes I want to sortrows,.
But as you can see the matrix has two column, the second column begin with 13 and this 13 value repeatred for number of rows. Thus, I need to sort the rows which has the same value 13 in scond column in ascending order, and the rows which has the next value after 13 in s cond column in decdening order.
For exampple:
AA = [ 5 13
7 13
6 13
4 14
5 14
8 14
5 16
8 16
7 16
9 16
3 20
6 20
8 20
9 20
. . ] so on
I need to generate the following format:
AA = [ 5 13
6 13
7 13
8 14
5 14
4 14
5 16
7 16
8 16
9 16
9 20
8 20
6 20
3 20
. . ] so on
Hope the example make my point clear.

댓글을 달려면 로그인하십시오.

채택된 답변

Stephen23
Stephen23 2020년 7월 10일
>> A = [5,13;7,13;6,13;4,14;5,14;8,14;5,16;8,16;7,16;9,16;3,20;6,20;8,20;9,20]
A =
5 13
7 13
6 13
4 14
5 14
8 14
5 16
8 16
7 16
9 16
3 20
6 20
8 20
9 20
>> B = sortrows(A,[2,1]);
>> X = ~mod(cumsum([true;diff(B(:,2))~=0]),2);
>> B(X,:) = sortrows(B(X,:),[2,-1])
B =
5 13
6 13
7 13
8 14
5 14
4 14
5 16
7 16
8 16
9 16
9 20
8 20
6 20
3 20

추가 답변 (1개)

Image Analyst
Image Analyst 2020년 7월 10일
I suggested sortrows() above, so did you actually try it? Did you do
AA = [ 5 13
7 13
6 13
4 14
5 14
8 14
5 16
8 16
7 16
9 16
3 20
6 20
8 20
9 20 ]
sortedAA = sortrows(AA, [2, 1])
to get
sortedAA =
5 13
6 13
7 13
4 14
5 14
8 14
5 16
7 16
8 16
9 16
3 20
6 20
8 20
9 20
If not, why not? Doesn't that do what you said you wanted to do?
  댓글 수: 1
Islam Hassan
Islam Hassan 2020년 7월 10일
Thanks for your reply.
However, the soredAA you generated is not exactly what I want. Please check the following illustration
Hope the illustration clear my point. Thanks in advance

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Import, Export, and Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by