Creating and ordering grids

2 views (last 30 days)
Ashraf El Gaaly
Ashraf El Gaaly on 8 Oct 2018
Commented: KSSV on 9 Oct 2018
I want to create a two column 20x20 grid (x,y) with 0.2 resolution on specific orders. First I know how to create the grid by fixing y everytime and populating x as follows
[y, x] = meshgrid(0:0.2:20);
grid = [x(:) y(:)];
The first order I want the points to be in is starts at (0,0) then jumps 20 points on x at the time until the end of that line is reached, i.e. (0,0) (2,0) (4,0)...(20,0) then starts at (0,2) and do the same (0,2) (2,2) (4,2)...(20,2) That's repeated until y =20. The same process starts again but now at (0.2,0). I was able to do that using 4 for loops as follows
grid=[];
for j = 0:0.2:1.8
for i = 0:0.2:1.8
for v = j:2:20
for u = i:2:20
p = [u v];
grid = [grid;p];
end
end
end
end
This code does the trick, but is there a more efficient way of doing that?
Now we come to the second way I want to order the points. I haven't been able to do that yet. I want to the same order as the one above starting at but ends at (10,10). starts at y=0 (0,0) (2,0) (4,0)...(20,0). Then y=1 (0,1) (2,1) (4,1)...(20,1). Until y =10 you it stops at x = 10 (0,10) (2,10) (4,10)...(10,10). Next you start at (0.2,0) and do the same until (9.8,10) Then another grid (matrix) that starts at the top (20,20) and goes from left to right (opposite to the above) until it end at (10,10). E.g. y=20 (20,20) (18,20)...(0,20). Then y=1 (20,18) (18,18)...(0,18). y =10 (20,10) (18,10) (16,10)...(10,10)
In another word, doing the same order as the one above but with two matrices, one starts at (0,0) and the second starts at (20,20) and they both meet at (10,10)
  1 Comment
KSSV
KSSV on 9 Oct 2018
Jeez...very confusing......Wont this work?
[X,Y] = meshgrid(0:2:20) ;

Sign in to comment.

Answers (0)

Categories

Find more on Simulink in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!