suppose i have latitude
-90
-60
-30
00
30
60
90
and longitude
-160 -120 -80 -40 00 40 80 120 160
i want output as
-90 -160
-60 -160
-30 -160
00 -160
30 -160
60 -160
90 -160
-90 -120
-60 -120
-30 -120
00 -120
30 -120
60 -120
90 -120
.
.
.
like that for all points. Any idea how could i do that ?

 採用された回答

Jan
Jan 2017 年 11 月 23 日
編集済み: Jan 2017 年 11 月 23 日

2 投票

lat = [-90 -60 -30 00 30 60 90]';
long = [ -160 -120 -80 -40 00 40 80 120 160 ];
nLat = length(lat);
nLong = length(long);
both = [repmat(lat, nLong, 1), repelem(long(:), nLat, 1)];
Alternatively for old Matlab versions, which do not have repelem:
tmp = repmat(long, nLat, 1);
both = [repmat(lat, nLong, 1), tmp(:)];

その他の回答 (2 件)

Andrei Bobrov
Andrei Bobrov 2017 年 11 月 23 日

2 投票

lat = [-90 -60 -30 00 30 60 90]';
long = [ -160 -120 -80 -40 00 40 80 120 160 ];
[x,y] = ndgrid(lat,long);
out = [x(:),y(:)];
Birdman
Birdman 2017 年 11 月 23 日
編集済み: Birdman 2017 年 11 月 23 日

1 投票

a=[-90 -60 -30 00 30 60 90];
b=[-160 -120 -80 -40 00 40 80 120 160];
a=a(:);b=b(:);
aa=repmat(a,length(b),1);
bb=repmat(b,length(a),1);
c=[aa bb]

3 件のコメント

pruth
pruth 2017 年 11 月 23 日
thank you for your reply
it is giving me an error
Error using horzcat Dimensions of matrices being concatenated are not consistent.
Birdman
Birdman 2017 年 11 月 23 日
this one works.
Jan
Jan 2017 年 11 月 23 日
@cvklpstunc: It works, but does not give the correct result: The 2nd column contains [-160; -120; -80; ...; 120; 160; -160; -120; ...] instead of the wanted [-160; -160; -160; ...]. It works, if you omit "b=b(:)" and reshape it after the repmat:
a = a(:);
aa = repmat(a,length(b),1);
bb = repmat(b,length(a),1);
c = [aa, bb(:)]

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

タグ

質問済み:

2017 年 11 月 23 日

コメント済み:

Jan
2017 年 11 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by