Borrar filtros
Borrar filtros

new array using average row of the old array

1 visualización (últimos 30 días)
babis
babis el 13 de Oct. de 2013
Comentada: babis el 13 de Oct. de 2013
I have an array M(1000,1000) and i want to build a new array N(1000,1000), where each element of N has the old value minus the average of its row (in M). If the element is zero no action will be taken. Also, from the average the zeros should be excluded.
Can you help me?
thank you in advance

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 13 de Oct. de 2013
Editada: Azzi Abdelmalek el 13 de Oct. de 2013
Edit
out=bsxfun(@minus,M,mean(M,2)).*not(~M)
%or
idx=M==0;
out=bsxfun(@minus,M,mean(M,2));
out(idx)=0
  6 comentarios
Azzi Abdelmalek
Azzi Abdelmalek el 13 de Oct. de 2013
Editada: Azzi Abdelmalek el 13 de Oct. de 2013
Ok try this
idx=M==0;
moyenne=sum(M,2)./sum(not(~M),2)
out=bsxfun(@minus,M,moyenne)
out(idx)=0
babis
babis el 13 de Oct. de 2013
thanks again this will do it

Iniciar sesión para comentar.

Más respuestas (1)

Andrei Bobrov
Andrei Bobrov el 13 de Oct. de 2013
ii = M == 0;
out = bsxfun(@minus,M,sum(M,2)./sum(~ii,2));
out(ii) = 0;

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by