MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   我们如何在matlab中加载符号表达式? (https://www.labfans.com/bbs/showthread.php?t=23700)

poster 2019-12-10 20:48

我们如何在matlab中加载符号表达式?
 
假设我们有类似u1 = 1/24 * h * sin(3 * t)-1 / 24 * h * sin(3 * t)* k + 1/24 * h * sin(t)-1 / 24 *的表达式h [I]k[/I] sin(t)。将其保存为.mat文件后,如何将其加载到matlab。我是matlab的新用户。我们使用的是matlab版本5.3的符号工具箱。使用char命令后,我们也可以将表达式保存在mat文件或其他文件中,例如fid = fopen('out.mat','r'); syms tk class(t); u0 = sin(t)+ k * cos(t)^ 2; u0 = char(u0); fprintf(fid,'u0 =%s',u0); fclose(fid);

据我所知,这会将u0保存在out.mat文件或所选名称中。如果您有更好的选择,请告诉我。因此,现在我的问题是如何加载它或如何在其他文件中使用此表达式。抱歉,没有提供有关此问题的完整信息。我已经尝试了命令load filename,但是它给出了“文件无法打开”的信息。我不知道。为什么?



[B]回答:[/B]

将变量保存和加载到.mat文件的正确方法是使用[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/save.html"]SAVE[/URL]和[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/load.html"]LOAD[/URL]函数。例如:

syms tk %# Declare your symbolic variables u0 = sin(t)+k*cos(t)^2; %# Make your symbolic equation save out.mat u0 %# Save u0 to out.mat 然后,您可以通过执行以下操作来加载变量u0 :

load out.mat %# Load u0 into your workspace 如果文件名存储为字符串,则还可以使用[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/save.html"]SAVE[/URL]和[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/load.html"]LOAD[/URL]的功能形式:

save('out.mat','u0'); %# Save u0 to out.mat load('out.mat'); %# Load u0 into your workspace

[url=https://stackoverflow.com/questions/3262901]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 03:05

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.