Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Is there a function to sum up the WeightedAVG for each same country?

1 Ansicht (letzte 30 Tage)
Pierre Lonfat
Pierre Lonfat am 19 Okt. 2016
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
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

Antworten (1)

Star Strider
Star Strider am 19 Okt. 2016
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 Kommentare
Pierre Lonfat
Pierre Lonfat am 19 Okt. 2016
Thank you for your answer ! How can i replace a value in a table ?
Star Strider
Star Strider am 19 Okt. 2016
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!

Translated by