Info

This question is closed. Reopen it to edit or answer.

How can i do the average between two cells of two matrices?

1 view (last 30 days)
Hi! I am having some serious issues with this problem. I am creating N=250 x,z coordinates. The odd N coordinates correspond to p1 and the even N coordinates correspond to p2. Once I have arrays of p1 and p2 I want to create p which is the average between p1 and p2 coordinates. I cant find the right code to create this array p(250,2) which is the average of both point p1 and p2. Also, N is the number of panels and p1 and p2 are the points where the panels connect and p is the point in the centerline of the panel.
Thank you very much for your help
clc
clear
NACAin=2405;
NACA=num2str(NACAin);
alpha=(5*pi/180);
N=250;
global x
global z
panelgen(NACA,250,alpha); %this generates coordinates x and z, which are two (250,1) arrays
global c
p1=zeros(250,2);
p2=zeros(250,2);
for i=1:N
c=evenorodd(i);
if c==1; %odd
p1(i,:)=[x(i),z(i)];
elseif c==0; %even
p2(i,:)=[x(i),z(i)];
end
p(i,:)=(p1(i,:)+p2(i,:))/2; <---
end
  3 Comments
Jacob
Jacob on 30 Mar 2014
Sorry for the confusion, but i find it hard to explain myself. There are N number of panels. The points connecting the panels are p1 for the odd 2D points (1,3,5...) and p2 for the even 2D points(2,4,6...). I need to find p, 250 points, which are the centerpoints of the panels, the center of the p1 and p2. Find below an example:
p(1,:)=(p1(1,:)+p2(2,:))/2
p(2,:)=(p1(3,:)+p2(2,:))/2
p(3,:)=(p1(3,:)+p2(4,:))/2
p(4,:)=(p1(5,:)+p2(4,:))/2
p(5,:)=(p1(5,:)+p2(6,:))/2
up to
p(250,:)=(p1(249,:)+p2(250,:))/2

Answers (0)

Community Treasure Hunt

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

Start Hunting!