removing elements of a cell array
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
James Connor
el 8 de Nov. de 2015
Comentada: James Connor
el 8 de Nov. de 2015
say we have a cell array
dictionary= 'abbreviately' 'abbreviation' 'abbreviator' 'abbreviatory' 'abbreviature' 'abby' 'abcoulomb' 'abdal'
I have written a code which returns x = 0 0 0 0 1 0 0
word='saddest'
newguess='e'
x=newguess==word
How do I delete the words from dictionary that are not equivalent for my x value and newguess letter 'e'. So x has a true value on the 5th position (after the 4 false values), which would mean I would like to delete all the words from dictionary if their 5th position letter does not equal 'e'. Thank you
0 comentarios
Respuesta aceptada
Walter Roberson
el 8 de Nov. de 2015
newdictionary = C( cellfun(@(C) length(C) >= 5 & C(5)==newguess, dictionary, 'Uniform', 0) );
5 comentarios
Walter Roberson
el 8 de Nov. de 2015
The code I gave assumed a cell array of strings, so it should be fine with that definition of your dictionary.
Más respuestas (0)
Ver también
Categorías
Más información sobre Structures 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!