Creating and ordering grids

2 ビュー (過去 30 日間)
Ashraf El Gaaly
Ashraf El Gaaly 2018 年 10 月 8 日
コメント済み: KSSV 2018 年 10 月 9 日
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 件のコメント
KSSV
KSSV 2018 年 10 月 9 日
Jeez...very confusing......Wont this work?
[X,Y] = meshgrid(0:2:20) ;

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeSimulink についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by