How to save a symbolic function into a .txt file
48 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello everyone,
I am trying to save a long symbolic function that I obtained as a result of my code into a .txt file. However, when I try to display it on the command window, it says "... Output truncated. Text exceeds maximum line length for Command Window display". As the solving procedure to obtain this function is quite time consuming, I would really like to save the result so that I can use it every time I want without having to go through the process again. Is there a way I can save a symbolic function (or a variable in general) permanently, for example in a .txt file?
I tried to use the command
save fileName.txt symFunc
but the resultant .txt file is completely unreadable.
I am using MATLAB R2021b. Any help is greatly appreciated. Thank you!
0 commentaires
Réponses (2)
Star Strider
le 18 Fév 2023
Try something like this —
syms t x(t) y(t)
symFunc = y == sin(x) + cos(x)
filename = 'Test.txt';
save(filename, 'symFunc','-mat')
file = which('Test.txt')
type(file) % Binary File
v = load(file,'-mat')
symFunc = v.symFunc
.
0 commentaires
John D'Errico
le 18 Fév 2023
Modifié(e) : John D'Errico
le 18 Fév 2023
You don't need to display it in the command window! For example, this expression will have 10001 terms in it.
syms x
P = expand((x+2)^10000);
Now you can save the variable P into a .mat file, and then load that file in again. There is no reason to worry about the command window truncating the result.
Or, if you want it in a more readable form, then convert it to a chanracter form.
Cp = char(P);
Again, use a semi-colon on the line so you don't trash the command window. Now save that into a text file if you prefer. A .mat file is by far preferable of course.
0 commentaires
Voir également
Catégories
En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!