フィルターのクリア

How to delete duplicate words (ie., two words combine) in cell arrays?

2 ビュー (過去 30 日間)
Jothi
Jothi 2015 年 6 月 20 日
コメント済み: Jothi 2015 年 6 月 20 日
Sir,
My cellarray contain the following words,
C= {'the best', 'work fast', the best', 'come fast', 'forget', 'tension', 'forget', 'come fast')
How to remove the duplicate cells ie., the best, come fast and forget are duplicate cell arrays.
The output file is C1={'the best', 'work fast', 'come fast', 'forget', 'tension'}
How to get this output.
Thanks.

採用された回答

cwshep
cwshep 2015 年 6 月 20 日
Probably not the fastest way...
function C = dedupeCell(C)
s = repmat(true,length(C),1);
for i = 1:length(C)
for j = 1:i-1
if strcmp(C{i},C{j})
s(i) = false;
end
end
end
C = C(s);
end
Results in:
>> C= {'the best', 'work fast', 'the best', 'come fast', 'forget', 'tension', 'forget', 'come fast'};
>> dedupeCell(C)
ans =
'the best' 'work fast' 'come fast' 'forget' 'tension'
Please take the time to put accurate code in your question (your cell definition is missing a quote, and is closed with a parenthesis).
  1 件のコメント
Jothi
Jothi 2015 年 6 月 20 日
Thank you sir.
It's working. I missed the closing parenthesis.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by