Help doing the average between successive (1,2) cells of two different arrays?
1 回表示 (過去 30 日間)
古いコメントを表示
Hi! I have a (250,2) array and i divide that array in two array: one contains the even rows and the other the odd rows. Those coordinates are points and i want to find the mid point of those two points(the odd one and the even one, between 1 and 2, then between 2 and 3, then between 3 and 4, and so on...) Is there a way to do this?
Thank you very much
0 件のコメント
採用された回答
Image Analyst
2014 年 3 月 30 日
編集済み: Image Analyst
2014 年 3 月 30 日
Try this:
a = rand(250, 2); % Sample data
% Make kernel to do the averaging.
kernel = [1;1]/2;
% Make every row of b the average or two adjacent rows of a.
b = conv2(a, kernel, 'valid')
It give you exactly what you're asking for. With your example data:
a =
4 3
2 2
3 3
4 2
b =
3 2.5
2.5 2.5
3.5 2.5
0 件のコメント
その他の回答 (1 件)
Azzi Abdelmalek
2014 年 3 月 30 日
編集済み: Azzi Abdelmalek
2014 年 3 月 30 日
a=rand(250,2)
a1=a(1:2:end,:);
a2=a(2:2:end,:);
b=(a2+a1)/2
4 件のコメント
Azzi Abdelmalek
2014 年 3 月 30 日
編集済み: Azzi Abdelmalek
2014 年 3 月 30 日
I think you need this
a =[ 4 3
2 2
3 3
4 2]
a1=a(1:end-1,:)
a2=a(2:end,:,:)
b=(a1+a2)/2
参考
カテゴリ
Help Center および File Exchange で Elementary Polygons についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!