フィルターのクリア

Remove Redundant Parentheses from String Expression

5 ビュー (過去 30 日間)
S H
S H 2016 年 6 月 7 日
編集済み: S H 2016 年 6 月 10 日
String contains a long expression. Part of it is:
'...+(G0*(G1-G2+G3))+((G4*(G5+G6)))-(((G7+G8))*((G9+G10+G11)))+...'
The redundant parentheses could be removed and the expression should look like:
'...+G0*(G1-G2+G3)+G4*(G5+G6)-(G7+G8)*(G9+G10+G11)+...'
Is there a simple Matlab script to do this?
  5 件のコメント
Walter Roberson
Walter Roberson 2016 年 6 月 8 日
https://github.com/ewiger/decade/tree/master/lib/mparser
S H
S H 2016 年 6 月 10 日
Thank you. I will look into https://github.com/ link.

サインインしてコメントする。

回答 (1 件)

Image Analyst
Image Analyst 2016 年 6 月 8 日
Recall that Azzi answered this, or something pretty much similar, and you accepted his answer in http://www.mathworks.com/matlabcentral/answers/287777#answer_224489
  4 件のコメント
Star Strider
Star Strider 2016 年 6 月 10 日
@S H —
Don’t get cheeky.
Revise the documentation for the Symbolic Math Toolbox simplify function.
S H
S H 2016 年 6 月 10 日
編集済み: S H 2016 年 6 月 10 日
Yes symbolic tool fixes this but it also shuffles all the terms and tries to sort them based on variable names. That is why I want to process this expression as string only.
This question takes finding matching parentheses one step further because repetition must also be accounted.
How to solve this includes the following steps:
1. write an algorithm to find matching parentheses for any existing pair
2. See if there is any pair with more than one repetition and then eliminate all redundants

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeString Parsing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by