summing random numerical excel data in matlab?
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
Nir Rattner
2014-8-5
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))]
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!