How to save a symbolic function into a .txt file
48 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
Star Strider
am 18 Feb. 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 Kommentare
John D'Errico
am 18 Feb. 2023
Bearbeitet: John D'Errico
am 18 Feb. 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 Kommentare
Siehe auch
Kategorien
Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!