Replacing repeated values in each row with zero

조회 수: 2 (최근 30일)
Ismaeel
Ismaeel 2017년 1월 7일
편집: Image Analyst 2017년 1월 7일
I have a matrix A:
A=[ 2 4 6 7 8 9 10 28 6 9 10 11;
2 4 6 7 8 9 10 28 10 21 22 24]
and I want to delete any repeated element in each row. The result should be as:
A=[ 2 4 6 7 8 9 10 28 0 0 0 11;
2 4 6 7 8 9 10 28 0 21 22 24]
Any idea? Thanks

답변 (1개)

Image Analyst
Image Analyst 2017년 1월 7일
Why do you want to do this? Is it homework? Are all A integers, or can they have fractional parts? Have you considered using histcounts() and look for numbers where the count is more than 2?
  댓글 수: 2
Ismaeel
Ismaeel 2017년 1월 7일
Thank you for the reply. No, it's not homework. The reason I want to do so is that each row has been created from previous processes and when I combine them (two rows combined to get the rows above), I get some of these repeated elements. The matrix I have is much greater in size than the one I mentioned. I haven't tried that function yet.
Ismaeel
Ismaeel 2017년 1월 7일
I forgot to add that all A are integer values, no fractional parts in it.

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

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by