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:
calculating growth without for loops

Subject: calculating growth without for loops

From: sujata

Date: 27 Feb, 2012 10:14:13

Message: 1 of 4

Hi,
I have the following vector
A = [50 ; 52 ; 49; 46; 50;51]

Anyone knows how to calculate the growth of matrix A i.e. (52/50) -1 ; (49/52) – 1 etc without using a for loop?
It should be element wise,

Thx in advance

Subject: calculating growth without for loops

From: Nasser M. Abbasi

Date: 27 Feb, 2012 10:30:31

Message: 2 of 4

On 2/27/2012 4:14 AM, sujata wrote:
> Hi,
> I have the following vector
> A = [50 ; 52 ; 49; 46; 50;51]
>
> Anyone knows how to calculate the growth of matrix A i.e. (52/50) -1 ; (49/52) – 1 etc without using a for loop?
> It should be element wise,
>
> Thx in advance

You mean like this?

  A(2:end)./A(1:end-1)-1

--Nasser

Subject: calculating growth without for loops

From: sujata

Date: 27 Feb, 2012 10:41:12

Message: 3 of 4

yes that is the one i mean. that is so easy

thx a lot


"Nasser M. Abbasi" <nma@12000.org> wrote in message <jifm09$jl7$1@speranza.aioe.org>...
> On 2/27/2012 4:14 AM, sujata wrote:
> > Hi,
> > I have the following vector
> > A = [50 ; 52 ; 49; 46; 50;51]
> >
> > Anyone knows how to calculate the growth of matrix A i.e. (52/50) -1 ; (49/52) – 1 etc without using a for loop?
> > It should be element wise,
> >
> > Thx in advance
>
> You mean like this?
>
> A(2:end)./A(1:end-1)-1
>
> --Nasser

Subject: calculating growth without for loops

From: Roger Stafford

Date: 27 Feb, 2012 20:36:10

Message: 4 of 4

"sujata" <sujatagp@gmail.com> wrote in message <jifl1k$4rn$1@newscl01ah.mathworks.com>...
> Hi,
> I have the following vector
> A = [50 ; 52 ; 49; 46; 50;51]
>
> Anyone knows how to calculate the growth of matrix A i.e. (52/50) -1 ; (49/52) – 1 etc without using a for loop?
> It should be element wise,
>
> Thx in advance
- - - - - - -
 Or how about

 diff(A)./A(1:end-1)

Roger Stafford

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