Filter löschen
Filter löschen

How to remove parentheses from all single words in a string?

2 Ansichten (letzte 30 Tage)
S H
S H am 5 Jun. 2016
Kommentiert: S H am 5 Jun. 2016
Example:
(G5)*((G6)*(G2+G4))+(G2)*(-(G4+G6)*(G1))+(G4)*(-(G6)*(G3))
Changes to:
G5*(G6*(G2+G4))+G2*(-(G4+G6)*G1)+G4*(-G6*G3)

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 5 Jun. 2016
Bearbeitet: Azzi Abdelmalek am 5 Jun. 2016
s='(G5)*((G6)*(G2+G4))+(G2)*(-(G4+G6)*(G1))+(G4)*(-(G6)*(G3))'
[i1,i2]=regexpi(s,'\<\([a-z0-9]+\>\)')
s([i1 i2])=[]
Or
s='(G5)*((G6)*(G2+G4))+(G2)*(-(G4+G6)*(G1))+(G4)*(-(G6)*(G3))'
out=regexprep(s,'\<\(([a-zA-Z0-9]+)\>\)','$1')

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by