martes, 20 de enero de 2009

Calculo de la mediana y la media en scilab

Mediana

M = [25, 25, 25, 25, 25;25,45,35,35,35;25,45,35,35,25;25,45,35,35,25;25,25,25,25,25]
[n,m]=size(M)
for i=2:n-1
for j=2:m-1
M(i,j)=fix((M(i-1,j-1)+M(i-1+j)+M(i-1,j+1)+M(i,j-1)+M(i,j)+M(i,j+1)+M(i+1,j-1)+M(i+1,j)+M(i+1,j+1))/9)
end
end


Media

M = [25, 25, 25, 25, 25;25,128,35,35,25;25,45,35,128,25;25,25,35,25,25]
[n,m]=size(M)
for i=2:n-1
for j=2:m-1
V = M(i-1:i+1,j-1)
V=[V,M(i-1:i+1,j)]
V=[V,M(i-1:i+1,j+1)]
sort(V)
M(i,j)=V(4)
end
end


1 comentario:

Unknown dijo...

como calcular la moda