How can i solve this?

3 次查看(过去 30 天)
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