http://www.mathworks.com/matlabcentral/newsreader/view_thread/314554
MATLAB Central Newsreader  storing output of computation into an array
Feed for thread: storing output of computation into an array
enus
©19942015 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Sun, 20 Nov 2011 18:15:14 +0000
storing output of computation into an array
http://www.mathworks.com/matlabcentral/newsreader/view_thread/314554#859001
Pg
hi,<br>
<br>
I h've an array A = [1 2 3; 56 7 8; 9 10 11]. Like this my actual A matrix size is 420x151. I want to compute moving average of each row of matrix A and store the output to a new matrix B of size (420mx151), where m is the sliding window size. In what way I can do so. Plz. let me know.

Sun, 20 Nov 2011 18:48:19 +0000
Re: storing output of computation into an array
http://www.mathworks.com/matlabcentral/newsreader/view_thread/314554#859003
Rune Allnor
On 20 Nov, 19:15, "Pg " <poulomi...@gmail.com> wrote:<br>
> hi,<br>
><br>
> I h've an array A = [1 2 3; 56 7 8; 9 10 11]. Like this my actual A matrix size is 420x151. I want to compute moving average of each row of matrix A and store the output to a new matrix B of size (420mx151), where m is the sliding window size. In what way I can do so. Plz. let me know.<br>
<br>
You are asking the wrong question.<br>
<br>
Before you ask *how*, you must first ask *what*<br>
you are going to do and *why*.<br>
<br>
I can't see anr yeason why applying an Mlength<br>
MA to an Nlength sequence would produce a<br>
result of length M*N. Find out what you are<br>
supposed to do first, and the 'how' is trivial.<br>
<br>
Rune

Sun, 20 Nov 2011 19:22:14 +0000
Re: storing output of computation into an array
http://www.mathworks.com/matlabcentral/newsreader/view_thread/314554#859004
Bruno Luong
"Pg " <poulomizca@gmail.com> wrote in message <jabg3i$sjk$1@newscl01ah.mathworks.com>...<br>
> hi,<br>
> <br>
> I h've an array A = [1 2 3; 56 7 8; 9 10 11]. Like this my actual A matrix size is 420x151. I want to compute moving average of each row of matrix A and store the output to a new matrix B of size (420mx151), where m is the sliding window size. In what way I can do so. Plz. let me know.<br>
<br>
If you are talking about moving average along rows (first dimension), then:<br>
<br>
B = conv2(A,ones(m,1),'valid') / m<br>
<br>
should do<br>
<br>
Bruno

Sun, 20 Nov 2011 19:25:29 +0000
Re: storing output of computation into an array
http://www.mathworks.com/matlabcentral/newsreader/view_thread/314554#859005
Roger Stafford
"Pg " <poulomizca@gmail.com> wrote in message <jabg3i$sjk$1@newscl01ah.mathworks.com>...<br>
> ..... I want to compute moving average of each row of matrix A and store the output to a new matrix B of size (420mx151), where m is the sliding window size. .....<br>
         <br>
Try this:<br>
<br>
B = [zero(size(A,1),1),cumsum(A,2)];<br>
B = (B(:,m+1:end)B(:,1:endm))/m;<br>
<br>
Note 1: On a 420 by 151 matrix, it is the rows that are of length 151, so it is these rows whose length will be reduced to 151(m1) length giving a 420 by 152m size to B.<br>
<br>
Note 2: The 'cumsum' function should not be used with excessively large numbers of summands since this can produce significantly larger amounts of accumulated round off error than would occur if each moving average sum were calculated separately.<br>
<br>
Roger Stafford

Mon, 21 Nov 2011 02:38:08 +0000
Re: storing output of computation into an array
http://www.mathworks.com/matlabcentral/newsreader/view_thread/314554#859030
Pg
I have already a program for moving average that I want to implement. Now this program gives output one by one if I take a for loop. Now what I want is to store each result into an empty array. It will be Like :<br>
<br>
for i=1:size(A,2) % for each row of matrix A<br>
....my moving avg. program<br>
..... output of moving average for each i<br>
end<br>
<br>
now I want to store these individual i values in a out put file or an empty matrix. That was my question? In what way i can do it? Sorry I cudn't frame my question properly before. <br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
"Roger Stafford" wrote in message <jabk79$d58$1@newscl01ah.mathworks.com>...<br>
> "Pg " <poulomizca@gmail.com> wrote in message <jabg3i$sjk$1@newscl01ah.mathworks.com>...<br>
> > ..... I want to compute moving average of each row of matrix A and store the output to a new matrix B of size (420mx151), where m is the sliding window size. .....<br>
>          <br>
> Try this:<br>
> <br>
> B = [zero(size(A,1),1),cumsum(A,2)];<br>
> B = (B(:,m+1:end)B(:,1:endm))/m;<br>
> <br>
> Note 1: On a 420 by 151 matrix, it is the rows that are of length 151, so it is these rows whose length will be reduced to 151(m1) length giving a 420 by 152m size to B.<br>
> <br>
> Note 2: The 'cumsum' function should not be used with excessively large numbers of summands since this can produce significantly larger amounts of accumulated round off error than would occur if each moving average sum were calculated separately.<br>
> <br>
> Roger Stafford