Borrar filtros
Borrar filtros

find the same values and average it out

3 visualizaciones (últimos 30 días)
Duncan
Duncan el 19 de Ag. de 2014
Respondida: Azzi Abdelmalek el 19 de Ag. de 2014
I have the following matrix A:
A =
66 2
66 3
66 4
67 6
67 3
68 5
69 6
69 3
what I would like to do is find the values that are the same in the first column and average the values in the second column and put it into a new matrix (B).
for example: I look for "66" and average the corresponding values in the second columns (i.e. 2,3,4) and the the mean is 3. So the first entry in matrix B will be:
B =
66 3

Respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 19 de Ag. de 2014
A =[ 66 2
66 3
66 4
67 6
67 3
68 5
69 6
69 3]
[ii,jj,kk]=unique(A(:,1))
out=[ii accumarray(kk,A(:,2),[],@mean)]

Categorías

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

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by