MATLAB Answers

Todd
0

I have a 20x1 vertical matrix. I want to take the averages of the pairs in order and display them in another matrix. How?

Asked by Todd
on 28 Jun 2012
To elaborate. I want to average the first and second numbers, third and fourth numbers, etc.. and display them again in a 10x1 matrix.

  0 Comments

Sign in to comment.

Tags

2 Answers

Answer by Image Analyst
on 28 Jun 2012
Edited by Image Analyst
on 28 Jun 2012
 Accepted Answer

Try this:
m = randi(5, [20 1]) % Generate sample data
% Reshape to a 10 by 2 array.
reshapedMatrix = reshape(m, [10,2])
% Get the means going across columns (within a row)
meansOfPairs = mean(reshapedMatrix, 2)

  0 Comments

Sign in to comment.


Answer by Honglei Chen
on 28 Jun 2012
Edited by Honglei Chen
on 28 Jun 2012

x = rand(20,1);
y = transpose(mean(reshape(x,2,10)))

  0 Comments

Sign in to comment.