remove null terms from a string and adjust signs
Ältere Kommentare anzeigen
Hi,
I have a string with more than thousands of terms in it. A small sample part of the string is
'...(G5)*((G6)*(G2+G4)+(G4)*(G2))+(G2)*((0)*(G4+G6)+(0)*(G3+G7)+(G4+G6)*(G1))+(G4)*((0)*(G6)+(G6)*(G7)-(0)*(G6))-(G9)*((G40+G60)*(0)-(G24+G26)*(G3)+(G14+G16)*(0))...'
I do not want to convert this string to symbolic expressions and I want to process it as a string because the location of each term is meaningful and important and the conversion to symbolic expression disregards it.
What I need to do is to remove all null terms from the string and adjust signs when negatives (or combination of negatives and positives) are multiplied together. the answer for the given part of the main string should be:
'...(G5)*((G6)*(G2+G4)+(G4)*(G2))+(G2)*((G4+G6)*(G1))+(G4)*((G6)*(G7))+(G9)*((G24+G26)*(G3))...'
Could you please show me how to do it using a very efficient code that I can plug in my m file?
Akzeptierte Antwort
Weitere Antworten (1)
Jos (10584)
am 9 Jun. 2016
str1 = strrep(str,'(0)*','')
str2 = strrep(str1,'*(0)','')
Kategorien
Mehr zu Characters and Strings finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!