Mostrar comentarios más antiguos
How would i strcmp two character strings with different numbers of rows? Also how can i display what the differences are between the two rows?
3 comentarios
Sven
el 1 de Nov. de 2011
Please give an example.
Are these strings with newlines, or are these cell arrays of strings?
Abra dog
el 1 de Nov. de 2011
Fangjun Jiang
el 1 de Nov. de 2011
Then ismember(),intersect() or setdiff() may be useful.
ismember({'a','b'},{'a','c','ab'})
intersect({'a','b'},{'a','c','ab'})
setdiff({'a','b'},{'a','c','ab'})
Respuesta aceptada
Más respuestas (1)
Walter Roberson
el 1 de Nov. de 2011
By definition, a character string only has one row.
If there is more than one row, you have a character array (or column vector.)
If you have two character arrays with the same width and the same number of rows, then
all(A==B,2)
will give you column vector of truth values of whether the rows match each other.
If you have two character arrays with different widths, then some would say that the two are never equal (because at the very least the number of trailing blanks would be different), and some would say that trailing blanks should be ignored (note: strcmp() explicitly includes trailing blanks!)
If you want to ignore trailing blanks and you have the same number of rows, then
cellfun(@isequal, cellstr(A), cellstr(B))
1 comentario
Abra dog
el 1 de Nov. de 2011
Categorías
Más información sobre Characters and Strings en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!