How can I average pairs of numbers within a vector?
조회 수: 3 (최근 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
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
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?
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!