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:
Vector Factorial

Subject: Vector Factorial

From: LIM CHIAN CHIAN

Date: 19 Feb, 2011 13:50:28

Message: 1 of 3

I wish to write a function file that capable of accepting a vector of scalar inputs of arbitrary length and computing a factorial solution for each element of that vector.
How can I write it by using "for" loops?

Subject: Vector Factorial

From: Roger Stafford

Date: 19 Feb, 2011 18:47:24

Message: 2 of 3

"LIM CHIAN CHIAN" wrote in message <ijohr4$87r$1@fred.mathworks.com>...
> I wish to write a function file that capable of accepting a vector of scalar inputs of arbitrary length and computing a factorial solution for each element of that vector.
> How can I write it by using "for" loops?
- - - - - - - - - -
  Assuming input v is a row vector of non-negtive integers, do this:

 f = [1,cumprod(1:max(v))];
 f = f(v+1);

No need for for-loops here.

Roger Stafford

Subject: Vector Factorial

From: Steven_Lord

Date: 21 Feb, 2011 01:04:24

Message: 3 of 3



"LIM CHIAN CHIAN" <limchianchian@gmail.com> wrote in message
news:ijohr4$87r$1@fred.mathworks.com...
> I wish to write a function file that capable of accepting a vector of
> scalar inputs of arbitrary length and computing a factorial solution for
> each element of that vector.

Use the GAMMA function.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

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