Removing square brackets from string

12 visualizaciones (últimos 30 días)
Peter Long  Nguyen
Peter Long Nguyen el 4 de Jun. de 2016
Comentada: Jay Mehta el 10 de Oct. de 2018
hey,
Right now i have a string A=[1101100111100010], is there anyway to remove the square brackets at the start and end of the string?
Thanks

Respuestas (2)

Walter Roberson
Walter Roberson el 4 de Jun. de 2016
A(2:end-1)
or
regexprep(A, '\[(.*)\]', '$1')
But first check that you really have a string. I suspect you might be looking at a cell array. If class(A) is cell instead of char then what you need instead is
A{1}

Image Analyst
Image Analyst el 4 de Jun. de 2016
Editada: Image Analyst el 4 de Jun. de 2016
An alternative way that also works:
A = '[1101100111100010]' % A is a string, not a numerical vector.
% Remove any and all left brackets.
A(A=='[') = []
% Remove any and all right brackets.
A(A==']') = []

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by