1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab help

  1. Jan 22, 2009 #1
    1. The problem statement, all variables and given/known data
    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.

    2. Relevant equations

    3. The attempt at a solution
    A = 0;
    for index = mean(x)
    A = A + x(index)/length(x);

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

    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.
  2. jcsd
  3. Jan 23, 2009 #2


    User Avatar
    Science Advisor

Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: Matlab help
  1. Matlab HELP ! (Replies: 4)

  2. Matlab help (Replies: 2)

  3. Matlab help (Replies: 2)

  4. Help with matlab (Replies: 7)

  5. MATLAB help (Replies: 2)