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

1 次查看(过去 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 个评论
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