Borrar filtros
Borrar filtros

Average returns for diffferent companies

2 visualizaciones (últimos 30 días)
Ana
Ana el 27 de Mzo. de 2014
Respondida: Jos (10584) el 27 de Mzo. de 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!

Respuestas (1)

Jos (10584)
Jos (10584) el 27 de Mzo. de 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)

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by