How to delete duplicate values from an array or a vector

조회 수: 210 (최근 30일)
sarah
sarah 2021년 2월 10일
댓글: sarah 2021년 2월 10일
How to delete duplicate values from an array or a vector
Hi, how do I delete duplicate values from an array or a vector provided that unique function is not used and that the place of the value does not remain empty or zero. The result is like this
a=[1 2 3 6 1 3 1];
a=[1 2 3 6]
b=[1 1 3
3 4 5
4 9 1];
b=[1 3 4 5 9]
  댓글 수: 5
KALYAN ACHARJYA
KALYAN ACHARJYA 2021년 2월 10일
편집: KALYAN ACHARJYA 2021년 2월 10일
@Matt J Exactly, so valid Question
:)
sarah
sarah 2021년 2월 10일
편집: sarah 2021년 2월 10일
This function is useless by working on the idea I am working on, which is the process of generating numbers through static equations to create a random 16 * 16 matrix. Thank you.

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

채택된 답변

Jan
Jan 2021년 2월 10일
편집: Jan 2021년 2월 10일
b=[1 1 3
3 4 5
4 9 1];
% The clean solution:
b = unique(b(:).')
% [1 3 4 5 9]
% Without unique:
bs = sort(b(:).');
result = bs([true, diff(bs) ~= 0])
% [1 3 4 5 9]
% For a stable output (order of elements does not change):
[bs, vec] = sort(b(:).');
uvec(vec) = [true, diff(bs) ~= 0];
result = b(uvec);
% [1 3 4 5 9]
  댓글 수: 1
sarah
sarah 2021년 2월 10일
Thank you very much, Mr. Jan, grateful to you very much

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by