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

2 次查看(过去 30 天)
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).

更多回答(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