Calculating the product of the elements in a certain range of an array?

4 ビュー (過去 30 日間)
Anna
Anna 2011 年 4 月 10 日
I have the following problem:
In my study i need to calculate a lot of returns on portfolios of different sizes, and i haven't managed to find a function that would allow for range-specific multiplication.
In other words i've only found functions that calculate the product of all the elements in an array whereas i would need the product of the elements between rows x and y in column z.
I would be really really grateful for your help!

回答 (1 件)

Paulo Silva
Paulo Silva 2011 年 4 月 10 日
m is your array
x=2; %start row
y=4; %end row
z=3; %column
prod(m(x:y,z)) %compute the product
Example
z
v
[1 2 3
x->4 5 6
7 8 9
y->10 11 12]
So the returned value will be 6*9*12=648
  2 件のコメント
Anna
Anna 2011 年 4 月 11 日
Oh I can define the range in prod. Thank you so much for the help!
Paulo Silva
Paulo Silva 2011 年 4 月 11 日
I added one example and change the variable names for the ones in your original question, I hope you understand now how it works.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by