Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.
|
|
|
Re: Getting a mean from x values in a matrix.
Posted:
Aug 13, 2014 10:13 AM
|
|
"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
|
|
|
|