How to find unique values in a matrix without looping over rows
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi,
I have an m by n matrix A that has repeat non-zero values in every row. The number of non-zero elements varies across rows. I would like to keep only unique values, but can't seem to figure out how to do that without looping. Matrix size is big, so I tried looping and it's not an option...
I tried using unique function, but can't get it to do what I need. I would appreciate any advice.
Thank you,
댓글 수: 0
답변 (2개)
Stephen23
2021년 1월 27일
M = randi([0,9],3,13)
W = sort(M,2);
W(diff(W,1,2)==0) = 0;
W = sort(W,2) % optional
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!