Removing square brackets from string

조회 수: 14 (최근 30일)
Peter Long  Nguyen
Peter Long Nguyen 2016년 6월 4일
댓글: Jay Mehta 2018년 10월 10일
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

답변 (2개)

Walter Roberson
Walter Roberson 2016년 6월 4일
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 2016년 6월 4일
편집: Image Analyst 2016년 6월 4일
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==']') = []

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by