From: Patrick on 9 May 2010 19:58 I have a number of 2-D arrays (13 x 9 double) and I would like to compute the element-by-element means, resulting in a 13 x 9 matrix of mean values. Seems like this should be a simple operation, analogous to multiplication (.*), but I've been unable to find a function that helps. My example more specifically: I have 31 13 x 9 matrices, each representing a day of a particular month, e.g. 'Dec01', 'Dec02', 'Dec03', etc. I would like to get the average monthly value of each element, e.g. 'Dec_avg', also a 13 x 9 matrix. Suggestions? Do I need to create a 3-D array, with a dimension representing the day? Thanks.
From: Tombo H on 9 May 2010 20:12 Didn't this work: averageMatrix = (1/31) * (Dec01+Dec02+Dec03+Dec04+Dec05+Dec06+Dec07+Dec08+Dec09+Dec10+Dec11+Dec12+Dec13+Dec14+Dec15+Dec16+Dec17+Dec18+Dec19+Dec20+Dec21+Dec22+Dec23+Dec24+Dec25+Dec26+Dec27+Dec28+Dec29+Dec30+Dec31); where each Decnn is a 13x9 double matrix?
From: John D'Errico on 9 May 2010 20:29 "Patrick " <gallagjo(a)interchange.ubc.ca> wrote in message <hs7i6c$b1v$1(a)fred.mathworks.com>... > I have a number of 2-D arrays (13 x 9 double) and I would like to compute the element-by-element means, resulting in a 13 x 9 matrix of mean values. Seems like this should be a simple operation, analogous to multiplication (.*), but I've been unable to find a function that helps. > > My example more specifically: I have 31 13 x 9 matrices, each representing a day of a particular month, e.g. 'Dec01', 'Dec02', 'Dec03', etc. I would like to get the average monthly value of each element, e.g. 'Dec_avg', also a 13 x 9 matrix. > > Suggestions? Do I need to create a 3-D array, with a dimension representing the day? > Thanks. Since that would be by far the most logical way to do it, why not? Naming separate arrays like that, with distinct numbers is a terrible approach. It forces you to do silly things, when a single call to mean would have sufficed otherwise. John
From: Patrick on 9 May 2010 20:36 Tombo H <tombo.hayworth(a)gmail.com> wrote in message <69e88147-ce61-4284-acac-48465a9012fd(a)k19g2000yqm.googlegroups.com>... > Didn't this work: > > averageMatrix = (1/31) * > (Dec01+Dec02+Dec03+Dec04+Dec05+Dec06+Dec07+Dec08+Dec09+Dec10+Dec11+Dec12+Dec13+Dec14+Dec15+Dec16+Dec17+Dec18+Dec19+Dec20+Dec21+Dec22+Dec23+Dec24+Dec25+Dec26+Dec27+Dec28+Dec29+Dec30+Dec31); > > where each Decnn is a 13x9 double matrix? Yes, although the command string could get quite long (I actually want to average more than a month's worth of days), this appears to be a simple solution that works. Thanks for the quick response. Patrick
From: Steven Lord on 9 May 2010 21:39 "Patrick " <gallagjo(a)interchange.ubc.ca> wrote in message news:hs7kdj$2j3$1(a)fred.mathworks.com... > Tombo H <tombo.hayworth(a)gmail.com> wrote in message > <69e88147-ce61-4284-acac-48465a9012fd(a)k19g2000yqm.googlegroups.com>... >> Didn't this work: >> >> averageMatrix = (1/31) * >> (Dec01+Dec02+Dec03+Dec04+Dec05+Dec06+Dec07+Dec08+Dec09+Dec10+Dec11+Dec12+Dec13+Dec14+Dec15+Dec16+Dec17+Dec18+Dec19+Dec20+Dec21+Dec22+Dec23+Dec24+Dec25+Dec26+Dec27+Dec28+Dec29+Dec30+Dec31); >> >> where each Decnn is a 13x9 double matrix? > > Yes, although the command string could get quite long (I actually want to > average more than a month's worth of days), this appears to be a simple > solution that works. Thanks for the quick response. In that case, don't create variables like that. Instead, since they're all the same size, store them as "pages" of a 3D array. dataForDecember = zeros(13, 9, 31) Then use MEAN specifying the dimension over which you want to take the mean. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
|
Next
|
Last
Pages: 1 2 Prev: Get keypress without locking/last key pressed? Next: MATLAB closes automatically |