remove null terms from a string and adjust signs
이전 댓글 표시
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?
채택된 답변
추가 답변 (1개)
Jos (10584)
2016년 6월 9일
str1 = strrep(str,'(0)*','')
str2 = strrep(str1,'*(0)','')
카테고리
도움말 센터 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!