Unmatched Matrix multiplication in Cell Arrays to create reducing count.

Hi,
I have an array of 1000 vectors of rates:
0.006
0.004
0.0029
...
I want to create a decreasing set of values starting from 100,000 which is created by multiplying each output number by the rate 1 step earlier:
1. 100,000
2. 100,000*0.006
3. This value *0.004
etc.
I would like the output to simply be an array of 1000 of these reducing counts, 100,000 ->

 採用された回答

José-Luis
José-Luis 2012 年 8 月 18 日

0 投票

Assuming your array is called data:
data=[100000;data];
data = cumprod(data);
Cheers!

3 件のコメント

John
John 2012 年 8 月 18 日
Hi, these aren't working:
I can't sort my data as I don't want rates in descending order.
I just need the first value in my ouput to be =100,000
subsequently, each value should be the product of the output cell one cell later), *vector of rates
so output cell 2 * vector cell 1
Therefore values in output should be:
100,000; 100,000*rate1; (100,000*rate1)*rate2; etc
José-Luis
José-Luis 2012 年 8 月 18 日
編集済み: José-Luis 2012 年 8 月 18 日
Whats the error that you get? cumprod does what you describe. If you append 100 000 to the beginning of your rates vector, it should work.
For more details:
help cumprod
John
John 2012 年 8 月 18 日
Sorry, my fault!! Answer was perfect!

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2012 年 8 月 18 日

0 投票

100000 * cumprod( sort(YourRates, 'descend') )

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2012 年 8 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by