MATLAB Answers

How do I product elements of a vector?

18 views (last 30 days)
cfjunior
cfjunior on 22 Oct 2013
Commented: cfjunior on 22 Oct 2013
Hi,
I have this matrix (3000 by 2) and I want the product of a range of elements in the second column. All of the elements are equal to 0.99 in a initial stage, but its gonna change after some further steps. I tried to use 'prod' but it didn't work...
Ex. matrix named 'aux'
prod(aux(2500,2):aux(2700,2)); It always returns me 0.99 no matter the range...
How do I do it?
tks

  3 Comments

Azzi Abdelmalek
Azzi Abdelmalek on 22 Oct 2013
Give a small example with expected result
cfjunior
cfjunior on 22 Oct 2013
or example:
A = [71 2; 72 2; 73 2; 74 2; 75 2];
and I want the product of the second element till fourth element (in sequence)
so, I want 2 x 2 x 2 = 8 ...

Sign in to comment.

Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 22 Oct 2013
Edited: Azzi Abdelmalek on 22 Oct 2013
A = [71 2; 72 2; 73 2; 74 2; 75 2];
prod(A(2:4,2))

  0 Comments

Sign in to comment.

Sign in to answer this question.