I have a problem removing the text and special characters from the string. For eg:
str = 'Accleration [ms^{{-}2}]';
The expected output: str_out = 'Acceleration';
I tried using the function regexprep but couldn't get the result as expected.
I have a problem removing the text and special characters from the string. For eg:
str = 'Accleration [ms^{{-}2}]';
The expected output: str_out = 'Acceleration';
I tried using the function regexprep but couldn't get the result as expected.
You can try
opens = str == '[';
closes = str == ']';
nestingcount = cumsum(opens - [0 closes(1:end-1)]);
outstr = str(nestingcount == 0);
Note that trimming trailing spaces was not part of your specification, you'll have to do that as well to get your example to work right.