From: Dave on
Dear Matlab gurus,

I need help trying to deal with periodicity in my programs.

So for a loop

for i=1:N

when some values in my program have terms like U(i+1) + U(i-1) etc.

I need U(i+1) when i=N to be U(N+1)=U(1) and likewise for the other

can I do this by creating a class say?

classdef i
% cst Summary of this class goes here
% Detailed explanation goes here

methods
if i==N+1
i=1
elseif i==0
i=N
end
end

end
From: Sean on
"Dave " <Davefulton(a)rocketmail.com> wrote in message <i26ubi$1m1$1(a)fred.mathworks.com>...
> Dear Matlab gurus,
>
> I need help trying to deal with periodicity in my programs.
>
> So for a loop
>
> for i=1:N
>
> when some values in my program have terms like U(i+1) + U(i-1) etc.
>
> I need U(i+1) when i=N to be U(N+1)=U(1) and likewise for the other
>

Why don't you just pad your vectors at both ends with the values you want and then run your for loop:
>>for ii = 2:N-1 %?
From: Steven_Lord on


"Dave " <Davefulton(a)rocketmail.com> wrote in message
news:i26ubi$1m1$1(a)fred.mathworks.com...
> Dear Matlab gurus,
>
> I need help trying to deal with periodicity in my programs.
> So for a loop
> for i=1:N
>
> when some values in my program have terms like U(i+1) + U(i-1) etc.
>
> I need U(i+1) when i=N to be U(N+1)=U(1) and likewise for the other
>
> can I do this by creating a class say?

Use the MOD function.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

From: Dave on
Thanks for the help guys will try both options
 | 
Pages: 1
Prev: Setting figure before plot
Next: MATLAB