필터 지우기
필터 지우기

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 CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by