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 个)
另请参阅
类别
在 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!