Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
periodicity and classes

Subject: periodicity and classes

From: Dave

Date: 21 Jul, 2010 13:57:06

Message: 1 of 4

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

Subject: periodicity and classes

From: Sean

Date: 21 Jul, 2010 14:24:04

Message: 2 of 4

"Dave " <Davefulton@rocketmail.com> wrote in message <i26ubi$1m1$1@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 %?

Subject: periodicity and classes

From: Steven_Lord

Date: 21 Jul, 2010 16:55:57

Message: 3 of 4



"Dave " <Davefulton@rocketmail.com> wrote in message
news:i26ubi$1m1$1@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@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

Subject: periodicity and classes

From: Dave

Date: 22 Jul, 2010 09:01:05

Message: 4 of 4

Thanks for the help guys will try both options

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us