new array using average row of the old array
조회 수: 1 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
Azzi Abdelmalek
2013년 10월 13일
편집: Azzi Abdelmalek
2013년 10월 13일
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
Azzi Abdelmalek
2013년 10월 13일
편집: Azzi Abdelmalek
2013년 10월 13일
Ok try this
idx=M==0;
moyenne=sum(M,2)./sum(not(~M),2)
out=bsxfun(@minus,M,moyenne)
out(idx)=0
추가 답변 (1개)
Andrei Bobrov
2013년 10월 13일
ii = M == 0;
out = bsxfun(@minus,M,sum(M,2)./sum(~ii,2));
out(ii) = 0;
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!