Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
Jothi
Jothi el 20 de Jun. de 2015
Comentada: Jothi el 20 de Jun. de 2015
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.

Respuesta aceptada

cwshep
cwshep el 20 de Jun. de 2015
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).

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by