Remove duplicates per row

4 views (last 30 days)
L. Edwin M.
L. Edwin M. on 11 Mar 2022
Commented: Voss on 11 Mar 2022
Hello! I only found answers about how to find duplicate rows with "unique"..
I want to remove all duplicate values per row so every value per row is unique:
Matrix A:
[1 1 2
1 2 2
3 2 3]
Output:
[1 2
1 2
2 3]
Thanks in advance!

Accepted Answer

Voss
Voss on 11 Mar 2022
A = [1 1 2; 1 2 2; 3 2 3];
A = num2cell(A,2);
B = cellfun(@unique,A,'UniformOutput',false);
try
B = cell2mat(B);
catch ME
% the arrays in the cells of B have different lengths
disp(ME.message);
end
disp(B);
1 2 1 2 2 3
  2 Comments
L. Edwin M.
L. Edwin M. on 11 Mar 2022
Perfect! Thanks a lot!
Voss
Voss on 11 Mar 2022
You're welcome!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!