Sum up dissimilar values in a matrix

조회 수: 1 (최근 30일)
Anum Ahmed
Anum Ahmed 2019년 11월 15일
댓글: Anum Ahmed 2019년 11월 15일
Hi All,
I have a 12*12 matrix and want to add the entries of matrix which are not equal to 1 and which are not similar to any other value in the Matrix. In short, I want to add up all the dissimilar values and the values not equal to 1.
Is there any short way to do so using loop function.
Many Thanks
Anum

채택된 답변

the cyclist
the cyclist 2019년 11월 15일
편집: the cyclist 2019년 11월 15일
If M is your array ...
sum(unique(M(M~=1)))
  댓글 수: 3
the cyclist
the cyclist 2019년 11월 15일
Sorry, meant to include the uniqueness in there. Edited to fix.
Anum Ahmed
Anum Ahmed 2019년 11월 15일
Awesome. Thanks a bundle...
Regards
Anum

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by