create a matrix of all possible combinations of 4 projects formed
2 ビュー (過去 30 日間)
古いコメントを表示

I want make matrix M. I have 4 project, project 1 with cost 4 and benefit 3, project 2 with cost 8 and benefit 4 , project 3 with cost 10 and benefit 3, project 4 with cost 8 and benefit 2. There are 16 portfolios formed from the four projects (including empty portfolio). Each row of the matrix M denotes each portfolio (combinations of four project). The first column of the matrix M is the cumulative cost, the second column of the matrix M is the cumulative benefit, the third to the sixth column shows the projects included in the portfolio. So, in the second line of 4 3 1 0 0 0 the cumulative cost is 4, the cumulative advantage is 3, project 1 is included in the portfolio, project 2 to project 4 is not included in the portfolio. The four projects and their costs and benefits are stored in excel file, which I then read into matlab with code.
[num,txt,raw]=xlsread('coba.xlsx',1);

0 件のコメント
採用された回答
Guillaume
2018 年 6 月 28 日
編集済み: Guillaume
2018 年 6 月 28 日
Project = [1; 2; 3; 4];
Cost = [4; 8; 10; 8];
Benefit = [3; 4; 3; 2];
M = dec2bin(0:2^numel(Project)-1) - '0'; %generate all combinations of project choice
M = [sum(Cost.' .* M, 2), sum(Benefit.' .* M, 2), M]
3 件のコメント
Guillaume
2018 年 6 月 28 日
編集済み: Guillaume
2018 年 6 月 28 日
Yes, the order of the rows will be different. Why does it matter? As far as I can tell there's no logic to the order of your matrix anyway.
If you get an error in the second line it's because you're using an old version of matlab (always a good idea to mention that). In versions prior to R2016b:
M = [sum(bsxfun(@times, Cost.', M), 2), sum(bsxfun(@times, Benefit.', M), 2), M]
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!