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: sum of result of two rows with third row
Replies: 3   Last Post: Aug 27, 2013 2:38 PM

 Messages: [ Previous | Next ]
 Alan Posts: 48 Registered: 7/30/13
Re: sum of result of two rows with third row
Posted: Aug 27, 2013 11:47 AM

"Shatrughan" wrote in message <kvigg9\$f9r\$1@newscl01ah.mathworks.com>...
> Hi,
>
> i am stuck with a problem in for loop.
>
> I have a data as below.
>
> A = [0 1 2 3 4 5 6 7 8 9]';
>
> in vector B, I want to apply a function mod as such mod ((0+1),5) which will be added to third element 2 and then compute the mod of ((previous result+2),5) and so on. my B vector should have these new values.
>
> Any help will be much appreciated.
>
> Thanks,
> Shatrughan

Should B = [0,1,3,1,0,0,1,3,1,0] ?

if so, then this should work for you

B = A;

for i = 2:length(A)
B(i) = mod(B(i-1)+B(i),5);
end

Date Subject Author
8/27/13 Shatrughan
8/27/13 Alan
8/27/13 Shatrughan
8/27/13 dpb