Got Questions? Get Answers.
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:
how I deal with negative index?

Subject: how I deal with negative index?

From: huda nawaf

Date: 23 Mar, 2010 16:47:23

Message: 1 of 5

hi,
how i can plot the signal if the coordinate is negative . i.e for ex. the point x(-1,1)
where matlab reject the negative index.
thanks in advance

Subject: how I deal with negative index?

From: Matt J

Date: 23 Mar, 2010 16:56:21

Message: 2 of 5

"huda nawaf" <halmamory@yahoo.com> wrote in message <hoarar$31k$1@fred.mathworks.com>...
> hi,
> how i can plot the signal if the coordinate is negative . i.e for ex. the point x(-1,1)
> where matlab reject the negative index.
================

Why would the coordinate be negative?

Subject: how I deal with negative index?

From: Wayne King

Date: 23 Mar, 2010 17:00:27

Message: 3 of 5

"huda nawaf" <halmamory@yahoo.com> wrote in message <hoarar$31k$1@fred.mathworks.com>...
> hi,
> how i can plot the signal if the coordinate is negative . i.e for ex. the point x(-1,1)
> where matlab reject the negative index.
> thanks in advance

Huda, Matlab will allow you plot negative numbers. It doesn't allow you to address elements of a vector (or matrix) with negative numbers. So

x = linspace(-2,2,100);
y=cos(2*pi*5*x);
plot(x,y)
% Note the negative numbers on both the x and y axes

is fine. But you cannot ask something like x(-2)

Wayne

Subject: how I deal with negative index?

From: huda nawaf

Date: 3 Apr, 2010 12:50:21

Message: 4 of 5

"Wayne King" <wmkingty@gmail.com> wrote in message <hoas3b$g6o$1@fred.mathworks.com>...
> "huda nawaf" <halmamory@yahoo.com> wrote in message <hoarar$31k$1@fred.mathworks.com>...
> > hi,
> > how i can plot the signal if the coordinate is negative . i.e for ex. the point x(-1,1)
> > where matlab reject the negative index.
> > thanks in advance
>
> Huda, Matlab will allow you plot negative numbers. It doesn't allow you to address elements of a vector (or matrix) with negative numbers. So
>
> x = linspace(-2,2,100);
> y=cos(2*pi*5*x);
> plot(x,y)
> % Note the negative numbers on both the x and y axes
>
> is fine. But you cannot ask something like x(-2)
>
> Wayne
thank you very much .
when is asked me to plot this signal , in question there is an one wave of sine, it should be get the same , but i don't how should determine the range of t(in question didnt give t , and are there relation between t and T?
v(t)=v0 sin(2*pi*t/T)
the code , I wrote it:
c=1;T=10
for t=-10:0.1:10
v(c)=v0 sin(2*pi*t/T)
c=c+1
end
plot(v)
many thanks

Subject: how I deal with negative index?

From: Sadik

Date: 3 Apr, 2010 14:49:08

Message: 5 of 5

Hi Huda,

Since it is voltage, t should start from zero. Also, you don't need a for loop here. The following should do what you are looking for:

t = linspace(0,T,1001); % so that t = [0, T/1000, 2*T/1000 and so on.
v = v0*sin(2*pi*t/T);
plot(t,v)

Best.

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