How can I average pairs of numbers within a vector?

4 次查看(过去 30 天)
I have two for loops here, and my output vector isn't quite what I need. How can I average two values within this loop?
deg= [-20,-175,-15,-125,-10,-5,0,5,10];
run= [1,2];
n=1;
for i= 1:length(deg)
for ii=1:length(run)
%
filename= ['q',num2str(deg(i)),'deg_2winglet_run',num2str(run(ii)),'.mat'];
temp= load(filename);
Fz(n)=mean(temp.F(:,3));
n=n+1;
end
end
Right now I am outputting a vector of the form [1_run1,1_run2,2_run1,2_run2,...] and I want to average the runs. I want the output vector to become [(1_run1)+(1_run2)/2, (2_run1)+(2_run2)/2, ...]. Is there a way to put this inside the for loops?
  2 个评论
per isakson
per isakson 2017-11-17
编辑:per isakson 2017-11-17
After reading only the title
>> vec = (1:12)
vec =
1 2 3 4 5 6 7 8 9 10 11 12
>> vec = reshape( vec, 2,[] )
vec =
1 3 5 7 9 11
2 4 6 8 10 12
>> mean( vec, 1 )
ans =
1.5000 3.5000 5.5000 7.5000 9.5000 11.5000
>>

请先登录,再进行评论。

回答(1 个)

Aarti Soni
Aarti Soni 2023-7-11
编辑:Aarti Soni 2023-7-11
What if the data is three dimensional?
for example: latitute X longitute X 60
how to take average in pair to make it latitute X longitute X 30?

标签

Community Treasure Hunt

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

Start Hunting!

Translated by