How can i solve this?

조회 수: 2 (최근 30일)
Arturzzaman Rustam
Arturzzaman Rustam 2020년 5월 27일
댓글: David Hill 2020년 5월 27일
For a given rectangular matrix A, it is required to find the number of elements that exceed in absolute value the arithmetic mean of all elements of this matrix.
A=rand(3,4)
M=mean(mean(A))
A(:)
x=abs(M)
c=0
fori = length(ans)
if (ans(i)>abs(x))
c=c+1
end;
i did this. Is this even the solution of that question?im new to matlab

채택된 답변

David Hill
David Hill 2020년 5월 27일
a=mean(abs(A),'all');
s=sum(A>a,'all');
  댓글 수: 2
David Hill
David Hill 2020년 5월 27일
Or,
a=mean(abs(A),'all');
s=nnz(A>a);
David Hill
David Hill 2020년 5월 27일
Sorry, I misunderstood you. You want to take the mean first, then abs. Here is a one-liner that will work for you.
s=nnz(A>abs(mean(A,'all')));

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by