Duplicate names in one cell column

조회 수: 2 (최근 30일)
hsi
hsi 2013년 10월 15일
편집: Jan 2013년 10월 16일
Hi,
I have a cell that contain several columns among them one text column (e.g., Person names). How can I check that the there is no duplicate names inside this column (If there is a duplicate names just assign duplicateName=true).
Thanks

답변 (2개)

Yatin
Yatin 2013년 10월 15일
Hi,
You can use the " hist " functions and the unique functions to determine if there are any duplicate values in your columns. Below is a sample code snippet:
arr = [5 3 1 5 6];
u = unique(arr);
n = hist(arr, u);
result = arr(n > 1);
Hope this helps.

Jan
Jan 2013년 10월 15일
편집: Jan 2013년 10월 16일
duplicateName = (numel(unique(C(:, index))) == size(C, 1))
[EDITED: Parenthesis fixed]
  댓글 수: 2
hsi
hsi 2013년 10월 15일
Thanks for the reply but I do not understand what is the index in the numel(unique(C(:, index))?
Cell example:
C = { '1st';'2st';'3st';'first';'2st'};
Jan
Jan 2013년 10월 16일
In your question you wrote:
I have a cell that contain several columns among them one text column
Then index is the index of the column, which contains the text. If C is this column already, use:
numel(unique(C)) == size(C, 1)

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

카테고리

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