Search All of the Math Forum:

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

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

 Search Thread: Advanced Search

 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
 Plain Text Reply

"Jakob " <jaw4000@hotmail.com> wrote in message
news:lsfqrj\$quc\$1@newscl01ah.mathworks.com...
> 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
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Date Subject Author
8/13/14 Jakob
8/13/14 Steven Lord

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