waywardEevee
waywardEevee

Reputation: 161

multiply all elements of a vector together MATLAB

If I have:

vec = 1:10

is there a function that will multiply all elements together (1*2*3*4*5...) of it without the need of a for loop?

Thanks!

Upvotes: 0

Views: 1727

Answers (1)

Romain
Romain

Reputation: 340

Use the function prod :

vec = 1:4;
prod(vec)

ans =

    24

Upvotes: 2

Related Questions