How do I output a MATLAB symbolic expression to a file?
8 views (last 30 days)
Show older comments
I would like to write a symbolic expression using the FPRINTF function.
Accepted Answer
MathWorks Support Team
on 27 Jun 2009
The symbolic expression has to be first converted into a character array (string) using the CHAR function. The '%s' specification is then used in conjunction with the FPRINTF function.
For example, consider a symbolic variable 'x'.
x = sym('x');
class(x)
Before using 'x' directly with FPRINTF, it has to converted using the CHAR function:
x = char(x)
The FPRINTF function can now be used to output 'x', by using the '%s' specification:
fprintf('%s',x)
Note that in this instance, the results of FPRINTF appear in the MATLAB Command Prompt because no open file was specified to write to. For more information regarding this function, enter the following at the MATLAB Command Prompt:
doc fprintf
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!