Average returns for diffferent companies
1 回表示 (過去 30 日間)
古いコメントを表示
Good afternoon,
I have the following set of data:

I want matlab to calculate the average of column 4, dependent on the values of column 3 (which are company tickers). That is, I want matlab to compute average returns of column 4 while column 3 refers to the same company (from row 1 to row 9 in this case).
Given that I have different number of observations in column 3 for each company (some have more data than others), is there a simple way to automatize this? For instance, to tell matlab that when Column 3, row i+1 == row i, do the average of the values of column 4 for this range.
I am new at matlab and any help would be much appreciated. Thank you!
0 件のコメント
回答 (1 件)
Jos (10584)
2014 年 3 月 27 日
Assuming DATA is a cell array holding your data, something along these lines could work:
[COMPANY,~,idx] = unique(DATA(:,3))
AVG = accumarray(idx, [DATA{:,4}],@mean)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!