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:
Creating a vector from differences in another vector

Subject: Creating a vector from differences in another vector

From: Ulrik Nash

Date: 23 Nov, 2009 11:34:04

Message: 1 of 5

Hi,

Suppose I have a vector A = [0 1 2 3 4 5]

now I wish to create another vector B from A

where B = [0-1 1-2 2-3 3-4 4-5]

How would I do that using MatLab?

Regards,

Ulrik.

Subject: Creating a vector from differences in another vector

From: kinor

Date: 23 Nov, 2009 12:26:03

Message: 2 of 5

"Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <hedrvc$kqb$1@fred.mathworks.com>...
> Hi,
>
> Suppose I have a vector A = [0 1 2 3 4 5]
>
> now I wish to create another vector B from A
>
> where B = [0-1 1-2 2-3 3-4 4-5]
>
> How would I do that using MatLab?
>
> Regards,
>
> Ulrik.

Hi Ulrik,

help diff

hth
kinor

Subject: Creating a vector from differences in another vector

From: Ulrik Nash

Date: 23 Nov, 2009 16:13:22

Message: 3 of 5

"kinor " <kinor.removethiswithdot@gmx.de> wrote in message <hedv0r$7ei$1@fred.mathworks.com>...
> "Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <hedrvc$kqb$1@fred.mathworks.com>...
> > Hi,
> >
> > Suppose I have a vector A = [0 1 2 3 4 5]
> >
> > now I wish to create another vector B from A
> >
> > where B = [0-1 1-2 2-3 3-4 4-5]
> >
> > How would I do that using MatLab?
> >
> > Regards,
> >
> > Ulrik.
>
> Hi Ulrik,
>
> help diff
>
> hth
> kinor

Hi Kinor,

I am not sure if I went in the right direction. Can you please elaborate?

Regards,

Ulrik.

Subject: Creating a vector from differences in another vector

From: Nathan

Date: 23 Nov, 2009 16:47:18

Message: 4 of 5

On Nov 23, 8:13 am, "Ulrik Nash" <u...@sam.sdu.dk> wrote:
> "kinor " <kinor.removethiswith...@gmx.de> wrote in message <hedv0r$7e...@fred.mathworks.com>...
> > "Ulrik Nash" <u...@sam.sdu.dk> wrote in message <hedrvc$kq...@fred.mathworks.com>...
> > > Hi,
>
> > > Suppose I have a vector A = [0 1 2 3 4 5]
>
> > > now I wish to create another vector B from A
>
> > > where B = [0-1 1-2 2-3 3-4 4-5]
>
> > > How would I do that using MatLab?
>
> > > Regards,
>
> > > Ulrik.
>
> > Hi Ulrik,
>
> > help diff
>
> > hth
> > kinor
>
> Hi Kinor,
>
> I am not sure if I went in the right direction. Can you please elaborate?
>
> Regards,
>
> Ulrik.

Using diff is almost what you need. Diff does this on A
diff(A) :
[1-0 2-1 3-2 4-3 5-4]
but you were looking for this:
somefunc(A)
[0-1 1-2 2-3 3-4 4-5]
which is equal to:
[(-1)-(-0) (-2)-(-1) (-3)-(-2) (-4)-(-3) (-5)-(-4)]
which is just
B = diff(-A)
%%%%%%%%%%%%
B =
    -1 -1 -1 -1 -1

-Nathan

Subject: Creating a vector from differences in another vector

From: kinor

Date: 23 Nov, 2009 16:47:21

Message: 5 of 5

"Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <heecb1$85f$1@fred.mathworks.com>...
> "kinor " <kinor.removethiswithdot@gmx.de> wrote in message <hedv0r$7ei$1@fred.mathworks.com>...
> > "Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <hedrvc$kqb$1@fred.mathworks.com>...
> > > Hi,
> > >
> > > Suppose I have a vector A = [0 1 2 3 4 5]
> > >
> > > now I wish to create another vector B from A
> > >
> > > where B = [0-1 1-2 2-3 3-4 4-5]
> > >
> > > How would I do that using MatLab?
> > >
> > > Regards,
> > >
> > > Ulrik.
> >
> > Hi Ulrik,
> >
> > help diff
> >
> > hth
> > kinor
>
> Hi Kinor,
>
> I am not sure if I went in the right direction. Can you please elaborate?
>
> Regards,
>
> Ulrik.


Hi Ulrik,

help diff gives you the information,
for your situation -diff(A) should do it

Best,
Kinor

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