Averaging positive and negative values seperately for each array in a matrix

조회 수: 3 (최근 30일)
PIRIL
PIRIL 2014년 12월 9일
댓글: PIRIL 2014년 12월 10일
Hi all,
I have a 40X1000 matrix and I want to average positive and negative values seperately for each array.
Lets say A=[0 2 2 -1 -7; 0 -1 -3 -2 6], I want an output file like output=[4 -4; 6 -2].
Does any of you know how to solve this ?
Many thanks

채택된 답변

Matt J
Matt J 2014년 12월 9일
pos=A>0;
neg=A<0;
output=[sum(A.*pos,2)./sum(pos,2) , sum(A.*neg,2)./sum(neg,2)]

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 12월 9일
A=[0 2 2 -1 -7; 0 -1 -3 -2 6]
x1=[arrayfun(@(x) mean(A(x,A(x,:)>0)),(1:size(A,1))') arrayfun(@(x) mean(A(x,A(x,:)<0)),(1:size(A,1))')]

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by