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:
"Index must be a positive integer or logical"

Subject: "Index must be a positive integer or logical"

From: Kevin

Date: 8 Feb, 2013 03:41:08

Message: 1 of 2

Hi,

I'm trying to plot a rect function under the requirement that
w(n) = {1 when (-M) <= n <= M , else 0}

M=25;
w = size(101);
j=1;

for n= -50:1:50;
    
    if (-M)<= n && n <= M
        w(j) = 1;
    else
        w(j) = 0;
    end
    j=j+1;
end

plot(w(j))

M=25

This works, except the plot is obviously from 25 - 25 and doesn't demonstrate w(n) but w(j)... is there a way to shift?.... or suggestions?

Subject: "Index must be a positive integer or logical"

From: Jos (10584)

Date: 8 Feb, 2013 10:12:08

Message: 2 of 2

"Kevin " <kmong92@hotmail.com> wrote in message <kf1s4k$8qh$1@newscl01ah.mathworks.com>...
> Hi,
>
> I'm trying to plot a rect function under the requirement that
> w(n) = {1 when (-M) <= n <= M , else 0}
>
> M=25;
> w = size(101);
> j=1;
>
> for n= -50:1:50;
>
> if (-M)<= n && n <= M
> w(j) = 1;
> else
> w(j) = 0;
> end
> j=j+1;
> end
>
> plot(w(j))
>
> M=25
>
> This works, except the plot is obviously from 25 - 25 and doesn't demonstrate w(n) but w(j)... is there a way to shift?.... or suggestions?

Pass all the elements of w, and add specific x-coordinates:
plot(-50:50, w)

help plot
could've helped you ...

~ Jos

Tags for 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