How to do vector calc for cost allocation

1 回表示 (過去 30 日間)
Pete sherer
Pete sherer 2020 年 7 月 31 日
編集済み: dpb 2020 年 7 月 31 日
The problem seems simple to do it using for loop, but I wonder if there's an efficient way to do below calculation.
costPerTotalUnit
0-1: 100%
1-2: 50%
2-3: 10%
3-10: 0%
unit/ cumsum/ cost
0.5/ 0.5/ 0.5*100%
0.3/ 0.8/ 0.3*100%
0.9/ 1.7/ 0.2*100% + 0.7* 50%
0.2/ 1.9/ 0.2*50%
0.5/ 2.4/ 0.1*50% + 0.4*10%
To do total calculation, it can be done quickly per below.
cumsumTotalUnit = 2.4;
costPercent = max(min(cumsumTotalUnit-(0:10-1),1),0);
costRate = [1 .5 .1 zeros(1,7)];
totalCost= costPercent.* costRate
(= 1.54)
However I want to be able to obtain the cost for each unit purchase. Maybe somekind of backward allocation?
Thanks,
PT

回答 (0 件)

カテゴリ

Help Center および File ExchangeHistorical Contests についてさらに検索

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by