필터 지우기
필터 지우기

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

채택된 답변

Image Analyst
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

추가 답변 (1개)

Azzi Abdelmalek
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
Jacob
Jacob 2014년 3월 30일
편집: Azzi Abdelmalek 2014년 3월 30일
clc
clear
a=ceil(4*rand(4,2))
a1=a(1:2:end,:)
a2=a(2:2:end,:)
b(1,:)=(a(1,:)+a(2,:))/2;
b(2,:)=(a(3,:)+a(2,:))/2;
b(3,:)=(a(3,:)+a(4,:))/2
Output=
a= 4 3
2 2
3 3
4 2
a1 =4 3
3 3
a2=2 2
4 2
b = 3.0000 2.5000
2.5000 2.5000
3.5000 2.5000
Which is exactly what I need but i need a formula to extend this to 250 rows(panels with 251 points connecting them)
Azzi Abdelmalek
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 CenterFile Exchange에서 Elementary Polygons에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by