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 to do negative array in Matlab

Subject: How to do negative array in Matlab

From: matlab_learner

Date: 21 Feb, 2010 01:33:11

Message: 1 of 4

Hello.

Just using Matlab for the first time.
I have an array that runs from -1 to 1, and I want to divide this into
20 equal parts.

How can I achieve this.

>> whos
  Name Size Bytes Class Attributes

  L 1x3 24 double
  M 1x1 8 double
  dx 1x3 24 double
  i 1x1 8 double
  x 0x0 0 double

>>

L=-1:1; % bounds
M=20;
dx = L/M;

for i=1:(M+1);
    x(i) = (i-1) * dx
end


Thank you.

Subject: How to do negative array in Matlab

From: ade77

Date: 21 Feb, 2010 01:50:05

Message: 2 of 4

matlab_learner <cibeji@gmail.com> wrote in message <995678e2-4a26-4684-9284-92c897959b78@c34g2000pri.googlegroups.com>...
> Hello.
>
> Just using Matlab for the first time.
> I have an array that runs from -1 to 1, and I want to divide this into
> 20 equal parts.
>
> How can I achieve this.
>
> >> whos
> Name Size Bytes Class Attributes
>
> L 1x3 24 double
> M 1x1 8 double
> dx 1x3 24 double
> i 1x1 8 double
> x 0x0 0 double
>
> >>
>
> L=-1:1; % bounds
> M=20;
> dx = L/M;
>
> for i=1:(M+1);
> x(i) = (i-1) * dx
> end
>
>
> Thank you.

for your specific example, see help linspace
linspace(-1,1,20)

Subject: How to do negative array in Matlab

From: matlab_learner

Date: 21 Feb, 2010 03:38:36

Message: 3 of 4

On Feb 20, 6:50 pm, "ade77 " <ade1...@gmail.com> wrote:
> matlab_learner <cib...@gmail.com> wrote in message <995678e2-4a26-4684-9284-92c897959...@c34g2000pri.googlegroups.com>...
> > Hello.
>
> > Just using Matlab for the first time.
> > I have an array that runs from -1 to 1, and I want to divide this into
> > 20 equal parts.
>
> > How can I achieve this.
>
> > >> whos
> >   Name      Size            Bytes  Class     Attributes
>
> >   L         1x3                24  double
> >   M         1x1                 8  double
> >   dx        1x3                24  double
> >   i         1x1                 8  double
> >   x         0x0                 0  double
>
> > L=-1:1;  % bounds
> > M=20;
> > dx = L/M;
>
> > for i=1:(M+1);
> >     x(i) = (i-1) * dx
> > end
>
> > Thank you.
>
> for your specific example, see help linspace
> linspace(-1,1,20)

But then I need to know the value of the space between each point.

How can i pull that out of linspace?

Subject: How to do negative array in Matlab

From: Sadik

Date: 21 Feb, 2010 04:25:04

Message: 4 of 4

If you get

x = linspace(-1,1,20);

Then,

dx = x(2) - x(1).

You could also say

diff(x)

which will output a constant vector of length 19 with elements

[dx dx ... dx]

Best.



matlab_learner <cibeji@gmail.com> wrote in message <7a085831-160e-411e-953e-316d9c269221@f17g2000prh.googlegroups.com>...
> On Feb 20, 6:50 pm, "ade77 " <ade1...@gmail.com> wrote:
> > matlab_learner <cib...@gmail.com> wrote in message <995678e2-4a26-4684-9284-92c897959...@c34g2000pri.googlegroups.com>...
> > > Hello.
> >
> > > Just using Matlab for the first time.
> > > I have an array that runs from -1 to 1, and I want to divide this into
> > > 20 equal parts.
> >
> > > How can I achieve this.
> >
> > > >> whos
> > >   Name      Size            Bytes  Class     Attributes
> >
> > >   L         1x3                24  double
> > >   M         1x1                 8  double
> > >   dx        1x3                24  double
> > >   i         1x1                 8  double
> > >   x         0x0                 0  double
> >
> > > L=-1:1;  % bounds
> > > M=20;
> > > dx = L/M;
> >
> > > for i=1:(M+1);
> > >     x(i) = (i-1) * dx
> > > end
> >
> > > Thank you.
> >
> > for your specific example, see help linspace
> > linspace(-1,1,20)
>
> But then I need to know the value of the space between each point.
>
> How can i pull that out of linspace?

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