using symbolic calculus on char strings (coming from a file)

조회 수: 1 (최근 30일)
genevois pierre
genevois pierre 2018년 11월 29일
편집: Walter Roberson 2018년 12월 1일
Hello, I'm currently using str2sym on char strings obtained from fgetl on a text file containing many lines of mathematical expressions that don't use Matlab syntax. More precisely, I perform some simple manipulations on those raw text strings (using regexprep for example), then I convert them using str2sym to make some simplifications, and I finally need to convert back the symbolic expressions to standard char strings in order to write them on a .m file (for later use). Two problems arise :
  • a warning arises when using str2sym ;
  • I don't know how to convert back the symbolic expressions to standard char strings
Can somebody help me ? Thanks in advance.
  댓글 수: 5
genevois pierre
genevois pierre 2018년 12월 1일
I apologize for having sent a wrong code ; here is a corrected version. Thank you for your help.
Walter Roberson
Walter Roberson 2018년 12월 1일
? str2sym does exist in MATLAB starting from r2017b which is your release .
If you have a scalar sym variable to convert back to character then use char()
If you have a nonscalar sym variable then arrayfun @char with uniform 0 . You use that instead of char() of the whole array because char applied to the whole array willl return a character vector that starts with aa call to matrix() which has to do with internal representation of the array .

댓글을 달려면 로그인하십시오.

채택된 답변

genevois pierre
genevois pierre 2018년 12월 1일
Thank you for your answer ; a warning when using str2sym could mean that this function will be removed in a future version ? However, I think the question can be closed now ...
  댓글 수: 1
Walter Roberson
Walter Roberson 2018년 12월 1일
편집: Walter Roberson 2018년 12월 1일
there are warnings in r2017b about using sym() for converting expressions to symbolic but sym2var was new in that release and would not have a warning . Well just maybe in the case where the character vector was in mupad syntax , I would have to test that .

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by