Filter löschen
Filter löschen

Average returns for diffferent companies

2 Ansichten (letzte 30 Tage)
Ana
Ana am 27 Mär. 2014
Beantwortet: Jos (10584) am 27 Mär. 2014
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!

Antworten (1)

Jos (10584)
Jos (10584) am 27 Mär. 2014
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)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by