summing random numerical excel data in matlab?

1 visualización (últimos 30 días)
Ronnel Jay
Ronnel Jay el 31 de Jul. de 2014
Respondida: Nir Rattner el 5 de Ag. de 2014
help pls. how about if i have this kind of excel file in which contains 2 columns (name and vaue) randomly arranged. what i want to output is the summarizing or addition of same name. how can i do this
name1 10
name2 20
name3 30
name4 40
name5 50
name5 20
name4 20
name3 10
name1 90
name2 10

Respuestas (1)

Nir Rattner
Nir Rattner el 5 de Ag. de 2014
You can use the “xlsread” function to read in the data from your Excel spreadsheet. Once the data is imported, you can use standard MATLAB operations.
For your next step of summing the data and grouped by the name, you can make use of the “unique” and “accumarray” functions. The “unique” function will index your string names. You can sum the values according to their indices using the “accumarray” function.
Here is some example code:
[num, txt, raw] = xlsread('Book1.xlsx');
[keys, ~, subs] = unique(txt);
results = [keys num2cell(accumarray(subs, num))]

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by