Info
この質問は閉じられています。 編集または回答するには再度開いてください。
Is there a function to sum up the WeightedAVG for each same country?
1 回表示 (過去 30 日間)
古いコメントを表示
For example, we would find a new table with only one row 'France' with WeightedABG_ = 0.006921 + 0.0045263.
Etc etc
Many thanks in advance !
Pierre

0 件のコメント
回答 (1 件)
Star Strider
2016 年 10 月 19 日
There is no single function, but it is straightforward to do that calculation. See sum the TWh/year (the last column) when the name of the countries (the first column) are similar that solves essentially the same problem.
2 件のコメント
Star Strider
2016 年 10 月 19 日
My pleasure.
The easiest way is to extract the data from the table with the table2cell function, then do the calculations. You can re-create the table with the new values after that, as I did in my code.
That will create a cell array for the ‘WeightedAverage’ column, so you will have to change my code slightly to be compatible with that.
Example:
WgtAvgCell = {randi(5,10,1)}; % Create Data
ic = randi(10, 10, 1); % Create Data
WgtAvgSum = accumarray(ic, WgtAvgCell{:}); % Calculate Sums By Country
Note the use of curly braces ‘{}’ to create a numeric array from the cell array. If the cell returned by table2cell is different, and the simpler syntax here does not work, use the cell2mat function to produce a numeric array from it.
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!