converting symbolic to string and printing to a file without 'piecewise' expression

3 次查看(过去 30 天)
I am attempting to print a symbolic expression to a file as a string. This piece of code worked correctly for me and then for some unknown reason didn't:
fprintf(fid,'''%s'';\n\n',char(C(i,j,2)));
By working correctly i mean that it printed out without a 'piecewise' in front of it...Does anyone know why its all of a sudden printing the output as 'piecewise'.
Thanks

回答(1 个)

Walter Roberson
Walter Roberson 2011-5-25
What does disp(C) show you ? If there is a conditional portion to the expression, it should show you piecewise(). Unless, that is, you want the formatted multi-line version that shows one case per line.
Possibly evalc(C(i,j,2)) would be useful for you
  3 个评论
Kyle Stanhouse
Kyle Stanhouse 2011-5-25
i guess i must have absentmindedly changed the file that computes and prints C, thats the only explanation....
Walter Roberson
Walter Roberson 2011-5-25
If you are printing a large symbolic matrix to a file so that you can use eval(), then you should consider instead using matlabFunction() to convert the matrix to a function handle or to write the function body to a file.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Symbolic Variables, Expressions, Functions, and Preferences 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by