summing random numerical excel data in matlab?

1 回表示 (過去 30 日間)
Ronnel Jay
Ronnel Jay 2014 年 7 月 31 日
回答済み: Nir Rattner 2014 年 8 月 5 日
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

回答 (1 件)

Nir Rattner
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))]

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by