Finding Mean of Vector x: A & B Equal?

  • Thread starter Thread starter magma_saber
  • Start date Start date
  • Tags Tags
    Mean Vector
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 2K views
magma_saber
Messages
73
Reaction score
0

Homework Statement


Below are two for loops that each find the mean of all the values in the vector x. A and B should be equal to the mean of the vector x.

Homework Equations


The Attempt at a Solution


A = 0;
for index = mean(x)
A = A + x(index)/length(x);
end

B = 0;
for index = mean(x)
B = B + index/length(x);
end

A file was provided that checks to see if its right. when i execute it, it says, "Attempted to access x(6); index out of bounds because numel(x)=5." what am i doing wrong? most of the code was already provided. all it asks is what "for index =" is equal to.
 
Physics news on Phys.org