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!