I am trying to develop a rules based string editing function in Matlab.
Suppose I have generated a string like the following:
myString = '/+*43/*/+34/5*2/*'
Supposed further that I wish to remove certain math operators according to a set of rules:
- A string cannot start with the '*' or '/' operators
- A string cannot end with any operator
- Any sequential operators are replaced by the first operator in that sequence unless it violates 1 and 2.
So for example the above string would reduce to:
myNewString = '+43/34/5*2'
Any method is fine to solve this problem, but a vectorized Boolean method would be preferred.
What I would like to do with this string is be able to perform a str2num on it and have it return a value and not throw errors.
Thanks!