The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Getting a mean from x values in a matrix.
Replies: 1   Last Post: Aug 13, 2014 10:13 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Steven Lord

Posts: 2,237
Registered: 9/26/13
Re: Getting a mean from x values in a matrix.
Posted: Aug 13, 2014 10:13 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Jakob " <> wrote in message
> Hey guys, i want to use in this case 360 values in a matrix to generate a
> mean in a new matrix. And i want a loop to continue doing that for the
> entire first matrix which in this case consist of 15440 values.

So what do you want to do with the left-over 320 elements of your matrix?

>> [360*42, 15440-360*42]

ans =

15120 320

> I've tried this :
> for N = 1:42
> X=0;
> for n = 1:360
> X=X+DATA((360*N-360)+n);
> n=n+1;
> end
> mean(N)=X/360; end
> The mean matrix however gets bigger than the 42 times im running it, and
> only the first mean seems to be realistic.

IF your matrix size were an integer multiple of the size of your "block" I
would suggest RESHAPE and calling the MEAN function with a dimension input
argument, but since it's not you need to decide first what to do with the
leftover chunk. Zero-pad to make your matrix size a multiple of 360,
ignoring the extra elements, or extracting the extra elements and taking
their MEAN (which would sum and divide by 320 instead of dividing by 360)
separately are three possible options.

Steve Lord
To contact Technical Support use the Contact Us link on

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.